Skip to content

Commit f6b252b

Browse files
committed
Port tests to py.test
1 parent 3e6d60f commit f6b252b

File tree

5 files changed

+18
-22
lines changed

5 files changed

+18
-22
lines changed

Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
# limitations under the License.
1414

1515
PYTHON?=python
16-
NOSETESTS?=nosetests
16+
PYTEST?=$(PYTHON) -m pytest
1717
FIGLEAF?=figleaf
1818
FIGLEAF2HTML?=figleaf2html
1919
DEMOOPTS?=
@@ -23,7 +23,7 @@ all:
2323

2424
.PHONY: test
2525
test:
26-
$(NOSETESTS)
26+
$(PYTEST)
2727

2828
.PHONY: demo
2929
demo:
@@ -36,7 +36,7 @@ selfdemo:
3636
.PHONY: coverage
3737
coverage:
3838
rm -rf .figleaf html
39-
$(FIGLEAF) `which $(NOSETESTS)`
39+
$(FIGLEAF) `which $(PYTEST)`
4040
$(FIGLEAF2HTML) -x figleaf_exclude
4141

4242
.PHONY: updatecopyright

figleaf_exclude

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
/System/.*.py
33
/Library/Python.*/.*.py
44
.*/tests/.*.py
5-
.*/nose.*
65
.*/pil/.*
76
lib/python2.*
87
python-support

setup.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,5 @@
3535
'regexlint=regexlint.cmdline:main',
3636
],
3737
},
38-
test_suite='nose.collector',
39-
tests_require=['nose'],
38+
tests_require=['pytest'],
4039
)

tests/test_charclass.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414

1515
import re
1616

17+
import pytest
18+
1719
from regexlint.parser import Regex
1820
from regexlint.charclass import *
1921

@@ -25,8 +27,8 @@
2527
(r'[0-9a-f]', None),
2628
(r'[\S]', r'[\S]'),
2729
(r'[\S\n]', r'[\S\n]'),
28-
(r'[^a-zA-Z0-9_]', '[\W]'),
29-
(r'[^a-zA-Z0-9]', '[\W_]'),
30+
(r'[^a-zA-Z0-9_]', r'[\W]'),
31+
(r'[^a-zA-Z0-9]', r'[\W_]'),
3032
(r'[^\S\n]', r'[\t\x0b\x0c\r ]'), # Double negative
3133
(r'[\r\n]', r'[\r\n]'),
3234
(r'[01]', r'[01]'),
@@ -39,18 +41,18 @@
3941
(r'[\x00-\xff]', r'[\w\W]'),
4042
]
4143

42-
def test_examples():
43-
for a, b in EXAMPLES:
44-
yield runner, a, b
4544

4645
def first_charclass(reg_text):
4746
r = Regex().get_parse_tree(reg_text, 0)
4847
return r.children[-1]
4948

49+
5050
def effective_flags(reg_text):
5151
return Regex().get_parse_tree(reg_text, 0).effective_flags
5252

53-
def runner(the_input, the_output):
53+
54+
@pytest.mark.parametrize('the_input, the_output', EXAMPLES)
55+
def test_examples(the_input, the_output):
5456
cc = first_charclass(the_input)
5557
codes = cc.matching_character_codes
5658
ignorecase = bool(effective_flags(the_input) & re.IGNORECASE)

tests/test_parser.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
from unittest import TestCase
2020
from pygments.token import Other
21+
import pytest
2122

2223
from regexlint.parser import Regex, Node, width, fmttree, \
2324
WHITESPACE, DIGITS, WORD
@@ -180,15 +181,12 @@ def test_complex_charclass(Self):
180181
#self.assertEqual(3, len(l))
181182

182183

183-
184-
def reconstruct_runner(pat):
184+
@pytest.mark.parametrize('pat', SAMPLE_PATTERNS)
185+
def test_reconstruct(pat):
185186
r = Regex.get_parse_tree(pat)
186187
rec = r.reconstruct()
187188
assert pat == rec
188189

189-
def test_reconstruct():
190-
for p in SAMPLE_PATTERNS:
191-
yield reconstruct_runner, p
192190

193191
SRE_CATS = {sre_constants.CATEGORY_SPACE: list(map(ord, WHITESPACE)),
194192
sre_constants.CATEGORY_DIGIT: list(map(ord, DIGITS)),
@@ -216,7 +214,9 @@ def expand_sre_in(x):
216214
else:
217215
raise NotImplementedError("Unknown type %s" % typ)
218216

219-
def charclass_runner(pat):
217+
218+
@pytest.mark.parametrize('pat', CHARCLASS_PATTERNS)
219+
def test_charclass(pat):
220220
r = Regex().get_parse_tree(pat)
221221
regexlint_version = r.children[0].matching_character_codes
222222
sre_parsed = sre_parse.parse(pat)
@@ -246,7 +246,3 @@ def charclass_runner(pat):
246246
print('missing:', sorted(set(golden) - set(regexlint_version)))
247247

248248
assert sorted(golden) == sorted(regexlint_version)
249-
250-
def test_charclass():
251-
for i in CHARCLASS_PATTERNS:
252-
yield charclass_runner, i

0 commit comments

Comments
 (0)