Skip to content

Commit b7e4f7c

Browse files
committed
Replace nose with pytest
1 parent 70dc337 commit b7e4f7c

28 files changed

+163
-297
lines changed

examples/examples.py

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,44 @@
11
import os
22
import collections
33

4-
from nose.tools import istest
5-
64
if os.environ.get("HAMCREST"):
75
from hamcrest import *
86
else:
97
from precisely.hamcrest import *
108

119

12-
User = collections.namedtuple("User", ["username", "email_address"])
10+
User = collections.namedtuple("User", ["username", "email_address"])
1311

1412

15-
@istest
1613
def test_anything():
1714
assert_that(1, anything())
1815

19-
@istest
2016
def test_equal_to():
2117
assert_that(1, equal_to(2))
2218

2319

24-
@istest
2520
def test_has_property_wrong_value():
2621
assert_that(User("bob", None), has_property("username", "bobbity"))
2722

2823

29-
@istest
3024
def test_has_property_missing():
3125
assert_that("bob", has_property("username", "bobbity"))
3226

3327

34-
@istest
3528
def test_has_properties_wrong_value():
3629
assert_that(User("bob", "[email protected]"), has_properties(
3730
username="bob",
3831
email_address="[email protected]",
3932
))
4033

4134

42-
@istest
4335
def test_all_of():
4436
assert_that(User("bob", "[email protected]"), all_of(
4537
has_property("username", "bob"),
4638
has_property("email_address", "[email protected]"),
4739
))
4840

4941

50-
@istest
5142
def test_contains_inanyorder_missing_elements():
5243
assert_that(
5344
[
@@ -61,7 +52,6 @@ def test_contains_inanyorder_missing_elements():
6152
)
6253

6354

64-
@istest
6555
def test_contains_inanyorder_extra_elements():
6656
assert_that(
6757
["apple", "banana"],
@@ -70,7 +60,6 @@ def test_contains_inanyorder_extra_elements():
7060

7161

7262

73-
@istest
7463
def test_contains_missing_elements():
7564
assert_that(
7665
[

makefile

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
.PHONY: test upload clean bootstrap
22

33
test:
4-
sh -c '. _virtualenv/bin/activate; nosetests tests'
4+
sh -c '. _virtualenv/bin/activate; py.test tests'
55
_virtualenv/bin/pyflakes precisely tests
66

77
test-all:
@@ -10,22 +10,22 @@ test-all:
1010
upload: test-all
1111
python setup.py sdist bdist_wheel upload
1212
make clean
13-
13+
1414
register:
1515
python setup.py register
1616

1717
clean:
1818
rm -f MANIFEST
1919
rm -rf dist
20-
20+
2121
bootstrap: _virtualenv
2222
_virtualenv/bin/pip install -e .
23-
ifneq ($(wildcard test-requirements.txt),)
23+
ifneq ($(wildcard test-requirements.txt),)
2424
_virtualenv/bin/pip install -r test-requirements.txt
2525
endif
2626
make clean
2727

28-
_virtualenv:
28+
_virtualenv:
2929
python3 -m venv _virtualenv
3030
_virtualenv/bin/pip install --upgrade pip
3131
_virtualenv/bin/pip install --upgrade setuptools

test-requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
nose>1,<2
1+
pytest
22
PyHamcrest==1.9.0
33
pyflakes==2.2.0

tests/__init__.py

Whitespace-only changes.

tests/all_elements_tests.py

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,24 @@
1-
from nose.tools import istest, assert_equal
2-
31
from precisely import all_elements, equal_to
42
from precisely.results import matched, unmatched
3+
from .testing import assert_equal
54

65

7-
@istest
8-
def matches_when_all_items_in_iterable_match():
6+
def test_matches_when_all_items_in_iterable_match():
97
matcher = all_elements(equal_to("apple"))
108

119
assert_equal(matched(), matcher.match(["apple", "apple"]))
1210

1311

14-
@istest
15-
def mismatches_when_actual_is_not_iterable():
12+
def test_mismatches_when_actual_is_not_iterable():
1613
matcher = all_elements(equal_to("apple"))
17-
14+
1815
assert_equal(
1916
unmatched("was not iterable\nwas 0"),
2017
matcher.match(0)
2118
)
2219

2320

24-
@istest
25-
def mismatches_when_item_in_iterable_does_not_match():
21+
def test_mismatches_when_item_in_iterable_does_not_match():
2622
matcher = all_elements(equal_to("apple"))
2723

2824
assert_equal(
@@ -31,15 +27,13 @@ def mismatches_when_item_in_iterable_does_not_match():
3127
)
3228

3329

34-
@istest
35-
def matches_when_iterable_is_empty():
30+
def test_matches_when_iterable_is_empty():
3631
matcher = all_elements(equal_to("apple"))
3732

3833
assert_equal(matched(), matcher.match([]))
3934

4035

41-
@istest
42-
def description_contains_descriptions_of_submatcher():
36+
def test_description_contains_descriptions_of_submatcher():
4337
matcher = all_elements(equal_to("apple"))
4438

4539
assert_equal(

tests/all_of_tests.py

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,39 @@
11
import collections
22

3-
from nose.tools import istest, assert_equal
4-
53
from precisely import all_of, has_attr, equal_to
64
from precisely.results import matched, unmatched
5+
from .testing import assert_equal
76

87

98
User = collections.namedtuple("User", ["username", "email_address"])
109

11-
@istest
12-
def matches_when_submatchers_all_match():
10+
def test_matches_when_submatchers_all_match():
1311
matcher = all_of(
1412
has_attr("username", equal_to("bob")),
1513
has_attr("email_address", equal_to("[email protected]")),
1614
)
17-
15+
1816
assert_equal(matched(), matcher.match(User("bob", "[email protected]")))
1917

2018

21-
@istest
22-
def mismatches_when_submatcher_mismatches():
19+
def test_mismatches_when_submatcher_mismatches():
2320
matcher = all_of(
2421
has_attr("username", equal_to("bob")),
2522
has_attr("email_address", equal_to("[email protected]")),
2623
)
27-
24+
2825
assert_equal(
2926
unmatched("was missing attribute username"),
3027
matcher.match("bobbity")
3128
)
3229

3330

34-
@istest
35-
def description_contains_descriptions_of_submatchers():
31+
def test_description_contains_descriptions_of_submatchers():
3632
matcher = all_of(
3733
has_attr("username", equal_to("bob")),
3834
has_attr("email_address", equal_to("[email protected]")),
3935
)
40-
36+
4137
assert_equal(
4238
"all of:\n * object with attribute username: 'bob'\n * object with attribute email_address: '[email protected]'",
4339
matcher.describe()

tests/any_of_tests.py

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,51 @@
11
import collections
22

3-
from nose.tools import istest, assert_equal
4-
53
from precisely import any_of, has_attr, equal_to
64
from precisely.results import matched, unmatched
5+
from .testing import assert_equal
76

87

98
User = collections.namedtuple("User", ["username", "email_address"])
109

11-
@istest
12-
def matches_when_submatchers_all_match():
10+
def test_matches_when_submatchers_all_match():
1311
matcher = any_of(
1412
has_attr("username", equal_to("bob")),
1513
has_attr("email_address", equal_to("[email protected]")),
1614
)
17-
15+
1816
assert_equal(matched(), matcher.match(User("bob", "[email protected]")))
1917

2018

21-
@istest
22-
def matches_when_any_submatchers_match():
19+
def test_matches_when_any_submatchers_match():
2320
matcher = any_of(
2421
equal_to("bob"),
2522
equal_to("jim"),
2623
)
27-
24+
2825
assert_equal(
2926
matched(),
3027
matcher.match("bob"),
3128
)
3229

3330

34-
@istest
35-
def mismatches_when_no_submatchers_match():
31+
def test_mismatches_when_no_submatchers_match():
3632
matcher = any_of(
3733
equal_to("bob"),
3834
equal_to("jim"),
3935
)
40-
36+
4137
assert_equal(
4238
unmatched("did not match any of:\n * 'bob' [was 'alice']\n * 'jim' [was 'alice']"),
4339
matcher.match("alice"),
4440
)
4541

4642

47-
@istest
48-
def description_contains_descriptions_of_submatchers():
43+
def test_description_contains_descriptions_of_submatchers():
4944
matcher = any_of(
5045
has_attr("username", equal_to("bob")),
5146
has_attr("email_address", equal_to("[email protected]")),
5247
)
53-
48+
5449
assert_equal(
5550
"any of:\n * object with attribute username: 'bob'\n * object with attribute email_address: '[email protected]'",
5651
matcher.describe()

tests/anything_tests.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
1-
from nose.tools import istest, assert_equal
2-
31
from precisely import anything
42
from precisely.results import matched
3+
from .testing import assert_equal
54

65

7-
@istest
8-
def matches_anything():
6+
def test_matches_anything():
97
assert_equal(matched(), anything.match(4))
108
assert_equal(matched(), anything.match(None))
119
assert_equal(matched(), anything.match("Hello"))
1210

1311

14-
@istest
15-
def description_is_anything():
12+
def test_description_is_anything():
1613
assert_equal("anything", anything.describe())
1714

tests/assert_that_tests.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
1-
from nose.tools import istest, assert_equal
2-
31
from precisely import assert_that, equal_to
2+
from .testing import assert_equal
43

54

6-
@istest
7-
def assert_that_does_nothing_if_matcher_matches():
5+
def test_assert_that_does_nothing_if_matcher_matches():
86
assert_that(1, equal_to(1))
97

108

11-
@istest
12-
def assert_that_raises_assertion_error_if_match_fails():
9+
def test_assert_that_raises_assertion_error_if_match_fails():
1310
try:
1411
assert_that(1, equal_to(2))
1512
assert False, "Expected AssertionError"

tests/close_to_tests.py

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
import functools
22

3-
from nose.tools import istest, assert_equal
4-
53
from precisely import close_to, is_sequence
64
from precisely.results import matched, unmatched
5+
from .testing import assert_equal
76

87

9-
@istest
10-
def close_to_matches_when_actual_is_close_to_value_plus_delta():
8+
def test_close_to_matches_when_actual_is_close_to_value_plus_delta():
119
matcher = close_to(42, 1)
1210
assert_equal(matched(), matcher.match(43))
1311
assert_equal(matched(), matcher.match(42.5))
@@ -17,8 +15,7 @@ def close_to_matches_when_actual_is_close_to_value_plus_delta():
1715
assert_equal(unmatched("was 40 (2 away from 42)"), matcher.match(40))
1816

1917

20-
@istest
21-
def close_to_matches_any_types_supporting_comparison_and_addition_and_subtraction():
18+
def test_close_to_matches_any_types_supporting_comparison_and_addition_and_subtraction():
2219
class Instant(object):
2320
def __init__(self, seconds_since_epoch):
2421
self.seconds_since_epoch = seconds_since_epoch
@@ -64,13 +61,11 @@ def __repr__(self):
6461
assert_equal(unmatched("was Instant(40) (Interval(2) away from Instant(42))"), matcher.match(Instant(40)))
6562

6663

67-
@istest
68-
def close_to_description_describes_value():
64+
def test_close_to_description_describes_value():
6965
matcher = close_to(42, 1)
7066
assert_equal("close to 42 +/- 1", matcher.describe())
7167

7268

73-
@istest
74-
def close_to_can_be_used_in_composite_matcher():
69+
def test_close_to_can_be_used_in_composite_matcher():
7570
matcher = is_sequence("a", "b", close_to(42, 1))
7671
assert_equal(matched(), matcher.match(("a", "b", 42)))

0 commit comments

Comments
 (0)