Skip to content

Commit

Permalink
Feature/test print (#137)
Browse files Browse the repository at this point in the history
* new: test: test for delete_rec (#132)

* chg: dev: add db instance for delay_commit check
* chg: dev: remove unused delete_rec test
* chg: test: not check delay commit on empty db test.
* chg: test: use simpler precise test for delete_rec
* fix: test: change pytest parametrize arg
* fix: test: fix instance of BukuDb
* fix: test: fix test.
* fix: test: logic on expected db len
* new: test: test for delete_rec
* new: test: test for delete_rec on empty database

* Needs timely commitment.

Removing the base implementation for rest APIs. At this point I believe it will
Be better handled by someone who needs it. The current contributions in this
area are very very infrequent. Defects and PRs remain pen over fortnights. It's
difficult to expect the same team to maintain the piece of code even if we ever
receive the full implementation from them.

* Roll ToDo list

* Feature/delete rec additional test data set (#133)

* new: test: additional data test set.

* new: test: test on non integer.

* chg: test: rename function for consistency.

* chg: test: change normalize function.

* chg: test: change max value for high var

* fix: test: use normalized index

* fix: test: remove 'max' as valid value

* chg: test: use hypothesis to test delete_rec index

* new: test: add hypothesis package

* chg: test: use hypothesis to test delete_rec index

* chg: test:  add hypothesis to travis

* chg: test: limit integer test.

* chg: dev: remove unused test

* fix: test: fix test on non integer.

* new: test: add big integer test on range in delete_rec method.

* fix: test: fix high low diff

* fix: test: skip only for python<3.5

* chg: test: change test_delete_rec_range_and_big_int

- remove skip
- use constant value instead sys.maxsize
- fix assert

* chg: test: use setup.py to manage test package instead travis

* chg: test: add tests extras on setup.py

* chg: test: change install test package.

* fix: test: fix whitespace

* fix: test: MAX_SQLITE_INT value

* chg: test: skip test for python<3.5

* fix: test: fix import

* chg: test: skip Impossible test

* chg: test: simplify test_delete_rec_on_non_interger

* Feature/tox test (#138)

* chg: test: mark slow test

* new: test: config for tox

* chg: test: mark function as non tox

* new: test: test print_rec with hypothesis

* chg: test: simplify test for print_single_rec

* fix: test: fix index test on test_print_rec_hypothesis

* fix: test: fix tox setting.

* fix: test: change test_print_single_rec to python3.5 only
  • Loading branch information
rachmadaniHaryono authored and jarun committed Mar 28, 2017
1 parent e2989b0 commit 7be3acc
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 112 deletions.
19 changes: 0 additions & 19 deletions api/requirements.txt

This file was deleted.

78 changes: 0 additions & 78 deletions api/server.py

This file was deleted.

22 changes: 11 additions & 11 deletions tests/test_buku.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
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")

Expand Down Expand Up @@ -134,17 +136,15 @@ def test_edit_at_prompt(nav, is_editor_valid_retval, edit_rec_retval):


@only_python_3_5
@pytest.mark.parametrize(
'idx, row0, row1, row2, row3, row4, row5',
product(
[0, 1],
[0],
['', 'row1'],
['', 'row2'],
[',', 'row3'],
['', 'row4'],
[0, 1],
)
@given(
idx=st.integers(),
row0=st.integers(),
row1=st.text(),
row2=st.text(),
row3=st.text(),
row4=st.text(),
row5=st.integers(),
)
def test_print_single_rec(idx, row0, row1, row2, row3, row4, row5):
"""test func."""
Expand Down
51 changes: 51 additions & 0 deletions tests/test_bukuDb.py
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,57 @@ def test_print_rec(capsys, caplog, setup):
assert err == ''


@given(
index=st.integers(min_value=-10, max_value=10),
low=st.integers(min_value=-10, max_value=10),
high=st.integers(min_value=-10, max_value=10),
is_range=st.booleans(),
)
def test_print_rec_hypothesis(caplog, setup, index, low, high, is_range):
"""test when index, low or high is less than 0."""
bdb = BukuDb()
if high < low:
n_high, n_low = low, high
else:
n_high, n_low = high, low

bdb.add_rec("http://one.com", "", parse_tags(['cat,ant,bee,1']), "")
db_len = 1

bdb.print_rec(index=index, low=low, high=high, is_range=is_range)

check_print = False
err_msg = ['Actual log:']
err_msg.extend(['{}:{}'.format(x.levelname, x.getMessage()) for x in caplog.records])

# negative index/range
if (is_range and any([low < 0, high < 0])):
assert any(x.levelname == "ERROR" for x in caplog.records)
assert any([x.getMessage() == "Negative range boundary" for x in caplog.records]), \
'\n'.join(err_msg)
# is_range
elif is_range:
check_print = True
# is_range == False
elif not is_range and 0 <= index <= db_len:
check_print = True
# no matching index
else:
assert any([x.levelname == "ERROR" for x in caplog.records]), \
'\n'.join(err_msg)
assert any([x.getMessage().startswith("No matching index") for x in caplog.records]), \
'\n'.join(err_msg)

if check_print:
assert not any([x.levelname == "ERROR" for x in caplog.records]), \
'\n'.join(err_msg)

# teardown
bdb.delete_rec(index=1)
caplog.handler.records.clear()
caplog.records.clear()


def test_list_tags(capsys, setup):
bdb = BukuDb()

Expand Down
5 changes: 1 addition & 4 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@
envlist = python33,python34,python35

[testenv]
deps=
pytest
pytest-cov
pytest-catchlog
commands =
pip install -e .[tests]
pip install -r requirements.txt
pytest --cov buku -vv {posargs}
;pytest --cov buku -vv -m 'not slowtest and not non_tox'{posargs}

0 comments on commit 7be3acc

Please sign in to comment.