Permalink
Browse files

Refactor tests with deprecated yield

Yield tests are deprecated in pytest.

Converted them to parameterized tests:
https://docs.pytest.org/en/latest/parametrize.html#pytest-mark-parametrize-parametrizing-test-functions
  • Loading branch information...
jvdzwaan committed Jul 25, 2018
1 parent 0174a09 commit 20ca3eee10137ceb6b60d7b594a00080d34d7c93
Showing with 31 additions and 33 deletions.
  1. +11 −11 recipyGui/tests/test_filters.py
  2. +20 −22 test/test_tinydb_utils.py
@@ -1,15 +1,15 @@
from nose.tools import assert_equal
import pytest
from recipyGui import highlight
def test_highlight():
@pytest.mark.parametrize("c,expected", [
({'txt': 'test', 'q': None}, 'test'),
({'txt': 'test', 'q': 'test'},
'<mark class="no-side-padding">test</mark>'),
({'txt': None, 'q': None}, 'None'),
])
def test_highlight(c, expected):
"""Test the highlight filter"""
cases = [
{'txt': 'test', 'q': None, 'out': 'test'},
{'txt': 'test', 'q': 'test',
'out': '<mark class="no-side-padding">test</mark>'},
{'txt': None, 'q': None, 'out': 'None'}
]
for c in cases:
yield assert_equal, highlight(text=c['txt'], query=c['q']), c['out']
assert highlight(text=c['txt'], query=c['q']) == expected
View
@@ -1,40 +1,38 @@
from nose.tools import assert_true, assert_false
import pytest
from recipyCommon.tinydb_utils import listsearch
def test_listsearch_flat_list_match():
@pytest.mark.parametrize('item', ['test', '/test/test.csv'])
def test_listsearch_flat_list_match(item):
q = 'test'
l = ['test', '/test/test.csv']
for item in l:
msg = 'listsearch({}, {}) does not return true'.format(q, item)
yield assert_true, listsearch(q, item), msg
msg = 'listsearch({}, {}) does not return true'.format(q, item)
assert listsearch(q, item), msg
def test_listsearch_flat_list_no_match():
@pytest.mark.parametrize('item', ['string', '/text/data.csv'])
def test_listsearch_flat_list_no_match(item):
q = 'test'
l = ['string', '/text/data.csv']
for item in l:
msg = 'listsearch({}, {}) does not return false'.format(q, item)
yield assert_false, listsearch(q, item), msg
msg = 'listsearch({}, {}) does not return false'.format(q, item)
assert not listsearch(q, item), msg
def test_listsearch_list_of_lists_match():
@pytest.mark.parametrize('item', [['string', 'hash-for-string'],
['/text/string.csv', 'another-hash'],
['blabla', 'string-in-hash']])
def test_listsearch_list_of_lists_match(item):
q = 'string'
l = [['string', 'hash-for-string'], ['/text/string.csv', 'another-hash'],
['blabla', 'string-in-hash']]
for item in l:
msg = 'listsearch({}, {}) does not return true'.format(q, item)
yield assert_true, listsearch(q, item), msg
msg = 'listsearch({}, {}) does not return true'.format(q, item)
assert listsearch(q, item), msg
def test_listsearch_list_of_lists_no_match():
@pytest.mark.parametrize('item', [['string', 'hash-for-string'],
['/text/data.csv', 'another-hash']])
def test_listsearch_list_of_lists_no_match(item):
q = 'test'
l = [['string', 'hash-for-string'], ['/text/data.csv', 'another-hash']]
for item in l:
msg = 'listsearch({}, {}) does not return false'.format(q, item)
yield assert_false, listsearch(q, item), msg
msg = 'listsearch({}, {}) does not return false'.format(q, item)
assert not listsearch(q, item), msg

0 comments on commit 20ca3ee

Please sign in to comment.