Permalink
Browse files

Merge pull request #1655 from jrioux/tests

Refactor the testing for "def test_" in test files.
  • Loading branch information...
smichr committed Nov 16, 2012
2 parents 6f4dd72 + 4e003bb commit 9e45cba6195adfc6225b7b93e53862f846cc05b8
@@ -527,7 +527,7 @@ def test_issue_1460():
# Note that solve will give
# multiple roots but match only gives one:
- #
+ #
# >>> solve(x**r-y**2,y)
# [-x**(r/2), x**(r/2)]
@@ -24,4 +24,3 @@ def test_adjoint():
assert Trace(Adjoint(Sq)) == conjugate(Trace(Sq))
assert Adjoint(Sq)[0, 1] == conjugate(Sq[1, 0])
-
@@ -8,4 +8,3 @@ def test_subs():
expr = Basic(a, Basic(b, c), Basic(d, Basic(e)))
result = Basic(d, Basic(b, c), Basic(a, Basic(f)))
assert subs(mapping)(expr) == result
-
@@ -43,6 +43,7 @@
gen_raise_re = re.compile(
r'^\s*(>>> )?(\.\.\. )?raise(\s+Exception|\s*(\(\s*)+Exception)')
old_raise_re = re.compile(r'^\s*(>>> )?(\.\.\. )?raise((\s*\(\s*)|\s+)\w+\s*,')
+test_suite_def_re = re.compile('^def\s+(?!(_|test))[^(]*\(\s*\)\s*:$')
def tab_in_leading(s):
@@ -106,11 +107,10 @@ def test(fname):
test_this_file(fname, test_file)
def test_this_file(fname, test_file):
- if re.match('.*test_.*\.py$', fname):
- _test_suite_defs(fname, test_file)
-
line = None # to flag the case where there were no lines in file
for idx, line in enumerate(test_file):
+ if re.match(r'.*test_.*\.py$', fname) and test_suite_def_re.match(line):
+ assert False, message_test_suite_def % (fname, idx + 1)
if line.endswith(" \n") or line.endswith("\t\n"):
assert False, message_space % (fname, idx + 1)
if line.endswith("\r\n"):
@@ -174,16 +174,6 @@ def test_this_file(fname, test_file):
check_directory_tree(EXAMPLES_PATH, test, exclude)
-def _test_suite_defs(fname, test_file):
- for idx, li in enumerate(test_file):
- if li.startswith('def '):
- if (re.match('.*\(\w\)\w:$', li) and
- not re.match('def +(_|(test_))', li)):
- assert False, \
- message_test_suite_def % \
- (fname, '%s: %s' % (idx, li))
-
-
def _with_space(c):
# return c with a random amount of leading space
return random.randint(0, 10)*' ' + c
@@ -301,6 +291,6 @@ def test_test_suite_defs():
"def foo():\n",
]
for c in candidates_ok:
- _test_suite_defs('', c)
+ assert test_suite_def_re.search(c) is None, c
for c in candidates_fail:
- raises(AssertionError, _test_suite_defs('', c))
+ assert test_suite_def_re.search(c) is not None, c

0 comments on commit 9e45cba

Please sign in to comment.