fix: test: change test (#149)

* fix: test: change priority on if-else branch

* fix: test: remove broken merged test code

* new: test: add win32 platform test for browser func

* chg: test: add noqa on print_single_rec

* new: test: test edit_update_rec with invalid input
This commit is contained in:
rachmadani haryono 2017-04-12 23:36:11 +08:00 committed by Arun Prakash Jana
parent b69007e9a6
commit 63a5883d58
No known key found for this signature in database
GPG Key ID: A75979F35C080412
3 changed files with 31 additions and 28 deletions

View File

@ -2290,7 +2290,7 @@ def prompt(obj, results, noninteractive=False, deep=False, subprompt=False):
break
def print_single_rec(row, idx=0):
def print_single_rec(row, idx=0): # NOQA
'''Print a single DB record
Handles both search result and individual record

View File

@ -9,8 +9,6 @@ import unittest
import pytest
from buku import is_int, parse_tags
from hypothesis import given
from hypothesis import strategies as st
only_python_3_5 = pytest.mark.skipif(sys.version_info < (3, 5), reason="requires python3.5")
@ -140,19 +138,6 @@ def test_edit_at_prompt(nav, is_editor_valid_retval, edit_rec_retval):
obj.add_rec(*edit_rec_retval)
@only_python_3_5
@given(
idx=st.integers(),
row0=st.integers(),
row1=st.text(),
row2=st.text(),
row3=st.text(),
row4=st.text(),
row5=st.integers(),
)
@pytest.mark.parametrize(
'field_filter, single_record',
product(range(4), [True, False])
@ -199,15 +184,18 @@ def test_is_int(string, exp_res):
@pytest.mark.parametrize(
'url, opened_url',
'url, opened_url, platform',
[
['http://example.com', 'http://example.com', ],
['example.com', 'http://example.com', ],
['http://example.com', 'http://example.com', 'linux'],
['example.com', 'http://example.com', 'linux'],
['http://example.com', 'http://example.com', 'win32'],
]
)
def test_browse(url, opened_url):
def test_browse(url, opened_url, platform):
"""test func."""
with mock.patch('buku.webbrowser') as m_webbrowser:
with mock.patch('buku.webbrowser') as m_webbrowser, \
mock.patch('buku.sys') as m_sys:
m_sys.platform = platform
import buku
buku.browse(url)
m_webbrowser.open.assert_called_once_with(opened_url, new=2)

View File

@ -548,7 +548,13 @@ def test_delete_rec_range_and_delay_commit(setup, low, high, delay_commit, input
res = bdb.delete_rec(
index=index, low=low, high=high, is_range=is_range, delay_commit=delay_commit)
if (low == 0 or high == 0) and input_retval != 'y':
if n_low < 0:
assert not res
assert len(bdb_dc.get_rec_all()) == db_len
# teardown
os.environ['XDG_DATA_HOME'] = TEST_TEMP_DIR_PATH
return
elif (low == 0 or high == 0) and input_retval != 'y':
assert not res
assert len(bdb_dc.get_rec_all()) == db_len
# teardown
@ -567,12 +573,6 @@ def test_delete_rec_range_and_delay_commit(setup, low, high, delay_commit, input
# teardown
os.environ['XDG_DATA_HOME'] = TEST_TEMP_DIR_PATH
return
elif n_low < 0:
assert not res
assert len(bdb_dc.get_rec_all()) == db_len
# teardown
os.environ['XDG_DATA_HOME'] = TEST_TEMP_DIR_PATH
return
assert res == exp_res
assert len(bdb.get_rec_all()) == exp_db_len
if delay_commit:
@ -867,6 +867,21 @@ def test_update_rec_update_all_bookmark(caplog, read_in_retval):
assert caplog.records[0].levelname == 'DEBUG'
@pytest.mark.parametrize(
'get_system_editor_retval, index, exp_res',
[
['none', 0, False],
['nano', -1, False],
]
)
def test_edit_update_rec_with_invalid_input(get_system_editor_retval, index, exp_res):
"""test method."""
with mock.patch('buku.get_system_editor', return_value=get_system_editor_retval):
import buku
bdb = buku.BukuDb()
res = bdb.edit_update_rec(index=index)
assert res == exp_res
# Helper functions for testcases