Skip to content

Commit

Permalink
Test for --parser option
Browse files Browse the repository at this point in the history
  • Loading branch information
jnothman committed Mar 19, 2017
1 parent 0912581 commit e205ef5
Showing 1 changed file with 25 additions and 8 deletions.
33 changes: 25 additions & 8 deletions tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import plistlib
import shutil
import sqlite3
import sys

import attr
import pytest
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit e205ef5

Please sign in to comment.