@@ -13,15 +13,19 @@ def testMethod():
13
13
return p .returncode == 0 , p .stdout
14
14
15
15
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 ]])
17
17
18
- test .description = lambda : "Types are specified and correctly used"
18
+ test .description = lambda : "types are specified and correctly used"
19
19
test .test = testMethod
20
20
test .fail = report
21
21
22
22
@t .test (1001 )
23
23
def doctest_ok (test ):
24
24
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 ] == '' )])
25
29
p = subprocess .run ([sys .executable or 'python3' , '-m' , 'doctest' , '-v' , test .fileName ], capture_output = True , universal_newlines = True )
26
30
if "Traceback" in p .stderr :
27
31
return False , p .stderr .splitlines ()[- 1 ]
@@ -30,16 +34,16 @@ def testMethod():
30
34
test_stats = test_stats_rex .search (p .stdout .splitlines ()[- 3 ])
31
35
test_pass = test_pass_rex .search (p .stdout .splitlines ()[- 2 ])
32
36
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
34
38
n_pass = int (test_pass .group (1 ))
35
39
if n_items == 0 :
36
40
return False , "Your program must use functions"
37
41
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) "
39
43
elif n_pass < n_tests :
40
44
return False , f"{ n_pass } out of { n_tests } examples passed"
41
45
return True
42
46
43
- test .description = lambda : "Doctests are specified and all examples pass"
47
+ test .description = lambda : "doctests are specified and all examples pass"
44
48
test .test = testMethod
45
49
test .fail = lambda info : info
0 commit comments