From e205ef5b3add7ef8ca5b78837eb5be64d0256e2c Mon Sep 17 00:00:00 2001 From: Joel Nothman Date: Thu, 9 Mar 2017 13:56:00 +1100 Subject: [PATCH] Test for --parser option --- tests/test_main.py | 33 +++++++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/tests/test_main.py b/tests/test_main.py index 0716fd5..96dd316 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -6,6 +6,7 @@ import plistlib import shutil import sqlite3 +import sys import attr import pytest @@ -101,20 +102,36 @@ def parse(self): def find_and_patch_entry(self, soup, entry): pass + class fake_module: + Parser = FakeParser + + expected = '''\ +Converting testtype docs from "foo" to "./{name}.docset". +Parsing documentation... +Added 1 index entries. +Adding table of contents meta data... +Adding to Dash.app... +''' + + # alternative 1: use --parser + sys.modules['fake_module'] = fake_module + with patch("os.system") as system: + result = runner.invoke( + main.main, ["foo", "--parser", "fake_module.Parser", "-n", "bah", + "-a", "-i", str(png_file)] + ) + assert expected.format(name='bah') == result.output + assert 0 == result.exit_code + assert ('open -a dash "./bah.docset"', ) == system.call_args[0] + + # alternative 2: patch doc2dash.parsers monkeypatch.setattr(doc2dash.parsers, "get_doctype", lambda _: FakeParser) with patch("os.system") as system: result = runner.invoke( main.main, ["foo", "-n", "bar", "-a", "-i", str(png_file)] ) - + assert expected.format(name='bar') == result.output assert 0 == result.exit_code - assert '''\ -Converting testtype docs from "foo" to "./bar.docset". -Parsing documentation... -Added 1 index entries. -Adding table of contents meta data... -Adding to Dash.app... -''' == result.output assert ('open -a dash "./bar.docset"', ) == system.call_args[0] # Again, just without adding and icon.