Feature/fix help test (#178)

* chg: test: dont hardcode the expected result

* fix: test: fix called_once arg

* fix: test: use mock_calls
This commit is contained in:
rachmadani haryono 2017-07-25 14:56:02 +08:00 committed by Arun Prakash Jana
parent bb9810c093
commit d440a294b9

View File

@ -10,26 +10,15 @@ def test_program_info(platform, file):
"""test method."""
with mock.patch('buku.sys') as m_sys:
import buku
prog_info_text = '''
SYMBOLS:
> url
+ comment
# tags
Version {}
Copyright © 2015-2017 {}
License: {}
Webpage: https://github.com/jarun/Buku
'''.format(buku.__version__, buku.__author__, buku.__license__)
file = mock.Mock()
if file is None:
buku.ExtendedArgumentParser.program_info()
else:
buku.ExtendedArgumentParser.program_info(file)
if platform == 'win32' and file == m_sys.stdout:
m_sys.stderr.write.assert_called_once_with(prog_info_text)
assert len(m_sys.stderr.write.mock_calls) == 1
else:
file.write.assert_called_once_with(prog_info_text)
assert len(file.write.mock_calls) == 1
def test_prompt_help():
@ -37,24 +26,7 @@ def test_prompt_help():
file = mock.Mock()
import buku
buku.ExtendedArgumentParser.prompt_help(file)
file.write.assert_called_once_with('''
keys:
1-N browse search result indices and/or ranges
a open all results in browser
s keyword [...] search for records with ANY keyword
S keyword [...] search for records with ALL keywords
d match substrings ('pen' matches 'opened')
r expression run a regex search
t [...] search bookmarks by a tag or show tag list
g [...][>>|>|<<][...] append, remove tags to/from indices and/or ranges
o [...] browse bookmarks by indices and/or ranges
p [...] print bookmarks by indices and/or ranges
w [editor|index] edit and add or update a bookmark
(tag list index fetches bookmarks by tag)
? show this help
q, ^D, double Enter exit buku
''')
assert len(file.write.mock_calls) == 1
def test_print_help():