Skip to content

Commit 77ee8d9

Browse files
committed
dontprint
1 parent 1ec7b3f commit 77ee8d9

File tree

1 file changed

+25
-25
lines changed

1 file changed

+25
-25
lines changed

tests/_basics.py

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -83,31 +83,31 @@ def report(output):
8383
def doctest_ok(test):
8484
"""doctests zijn voldoende aanwezig en geven allemaal akkoord"""
8585
def testMethod():
86-
# with open(test.fileName, 'r') as source_file:
87-
# source = source_file.read()
88-
# functions = re.findall(r'def\s+(\w+)\(([^\)]*)\)[^-]+(->\s*([\w\[,\] _]+))?:', source)
89-
# n_functions_not_returning = len([function for function in functions if ('file' in function[1] or function[3] == 'None' or function[3] == '')])
90-
# n_functions = len(functions)
91-
# p = subprocess.run([sys.executable or 'python3', '-m', 'doctest', '-v', test.fileName], capture_output=True, universal_newlines=True)
92-
# if "Traceback" in p.stderr:
93-
# return False, p.stderr.splitlines()[-1]
94-
# test_stats_rex = re.compile('(\d*) tests in (\d*) items')
95-
# test_pass_rex = re.compile('(\d*) passed and (\d*) failed')
96-
# test_stats = test_stats_rex.search(p.stdout.splitlines()[-3])
97-
# test_pass = test_pass_rex.search(p.stdout.splitlines()[-2])
98-
# n_tests = int(test_stats.group(1))
99-
# n_items = int(test_stats.group(2))-1
100-
# n_tested = n_items-n_functions_not_returning
101-
# n_pass = int(test_pass.group(1))
102-
# if n_functions == 0:
103-
# return False, "je programma moet functies gebruiken (of type hints ontbreken!)"
104-
# elif n_tested == 0:
105-
# # geen testbare functies blijkbaar?
106-
# return True
107-
# elif n_tested > 0 and n_tests // n_tested < 2:
108-
# return False, f"{n_tests} voorbeelden bij {n_tested} testbare functies is niet genoeg \n (we tellen alleen functies die iets returnen)"
109-
# elif n_pass < n_tests:
110-
# return False, f"{n_pass} van {n_tests} voorbeelden slagen"
86+
with open(test.fileName, 'r') as source_file:
87+
source = source_file.read()
88+
functions = re.findall(r'def\s+(\w+)\(([^\)]*)\)[^-]+(->\s*([\w\[,\] _]+))?:', source)
89+
n_functions_not_returning = len([function for function in functions if ('file' in function[1] or function[3] == 'None' or function[3] == '')])
90+
n_functions = len(functions)
91+
p = subprocess.run([sys.executable or 'python3', '-m', 'doctest', '-v', test.fileName], capture_output=True, universal_newlines=True)
92+
if "Traceback" in p.stderr:
93+
return False, p.stderr.splitlines()[-1]
94+
test_stats_rex = re.compile('(\d*) tests in (\d*) items')
95+
test_pass_rex = re.compile('(\d*) passed and (\d*) failed')
96+
test_stats = test_stats_rex.search(p.stdout.splitlines()[-3])
97+
test_pass = test_pass_rex.search(p.stdout.splitlines()[-2])
98+
n_tests = int(test_stats.group(1))
99+
n_items = int(test_stats.group(2))-1
100+
n_tested = n_items-n_functions_not_returning
101+
n_pass = int(test_pass.group(1))
102+
if n_functions == 0:
103+
return False, "je programma moet functies gebruiken (of type hints ontbreken!)"
104+
elif n_tested == 0:
105+
# geen testbare functies blijkbaar?
106+
return True
107+
elif n_tested > 0 and n_tests // n_tested < 2:
108+
return False, f"{n_tests} voorbeelden bij {n_tested} testbare functies is niet genoeg \n (we tellen alleen functies die iets returnen)"
109+
elif n_pass < n_tests:
110+
return False, f"{n_pass} van {n_tests} voorbeelden slagen"
111111
return True
112112

113113
test.test = testMethod

0 commit comments

Comments
 (0)