Skip to content

Commit e675ebd

Browse files
committed
subtract none-returning functions from doctest check
1 parent b112934 commit e675ebd

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

tests/_extensions.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,19 @@ def testMethod():
1313
return p.returncode == 0, p.stdout
1414

1515
def report(output):
16-
return 'Line ' + '\n - Line '.join([':'.join(i.split(':')[1:]) for i in output.splitlines()[:-1]])
16+
return 'line ' + '\n - line '.join([':'.join(i.split(':')[1:]) for i in output.splitlines()[:-1]])
1717

18-
test.description = lambda: "Types are specified and correctly used"
18+
test.description = lambda: "types are specified and correctly used"
1919
test.test = testMethod
2020
test.fail = report
2121

2222
@t.test(1001)
2323
def doctest_ok(test):
2424
def testMethod():
25+
with open(test.fileName, 'r') as source_file:
26+
source = source_file.read()
27+
functions = re.findall(r'def\s+(\w+)\(([^\)]*)\)[^-]+(->\s*([\w\[,\] _]+))?:', source)
28+
n_functions_not_returning = len([function for function in functions if ('file' in function[1] or function[3] == 'None' or function[3] == '')])
2529
p = subprocess.run([sys.executable or 'python3', '-m', 'doctest', '-v', test.fileName], capture_output=True, universal_newlines=True)
2630
if "Traceback" in p.stderr:
2731
return False, p.stderr.splitlines()[-1]
@@ -30,16 +34,16 @@ def testMethod():
3034
test_stats = test_stats_rex.search(p.stdout.splitlines()[-3])
3135
test_pass = test_pass_rex.search(p.stdout.splitlines()[-2])
3236
n_tests = int(test_stats.group(1))
33-
n_items = int(test_stats.group(2))-1
37+
n_items = int(test_stats.group(2))-1-n_functions_not_returning
3438
n_pass = int(test_pass.group(1))
3539
if n_items == 0:
3640
return False, "Your program must use functions"
3741
elif n_tests // n_items < 2:
38-
return False, f"{n_tests} examples in {n_items} functions is not quite enough"
42+
return False, f"{n_tests} examples in {n_items} functions is not quite enough \n (we only count functions that return something)"
3943
elif n_pass < n_tests:
4044
return False, f"{n_pass} out of {n_tests} examples passed"
4145
return True
4246

43-
test.description = lambda: "Doctests are specified and all examples pass"
47+
test.description = lambda: "doctests are specified and all examples pass"
4448
test.test = testMethod
4549
test.fail = lambda info: info

0 commit comments

Comments
 (0)