buku/tests/test_ExtendedArgumentParser.py
rachmadani haryono 8fc2775b48 Feature/test (#130)
* new: test: test for BukuHTMLParser class

* new: test: test for BukuCrypt class

* chg: test: change getpass patch path

* new: test: test for ExtendedArgumentParser class

* new: test: test for functions.

* chg: test: fix warning for caplog

* chg: test:  exclude some test for python3.5 only
2017-03-18 19:11:59 +05:30

65 lines
2.0 KiB
Python

"""test module."""
from itertools import product
from unittest import mock
import pytest
@pytest.mark.parametrize("platform, file", product(['win32', 'linux'], [None, mock.Mock()]))
def test_program_info(platform, file):
"""test method."""
with mock.patch('buku.sys') as m_sys:
import buku
prog_info_text = '''
SYMBOLS:
> title
+ 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)
else:
file.write.assert_called_once_with(prog_info_text)
def test_prompt_help():
"""test method."""
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
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
''')
def test_print_help():
"""test method."""
file = mock.Mock()
import buku
obj = buku.ExtendedArgumentParser()
obj.program_info = mock.Mock()
obj.print_help(file)
obj.program_info.assert_called_once_with(file)