2222## Run selected tests from {name} from StdLib
2323##
2424
25- import unittest
26- import sys
27-
28- from iptest import run_test
25+ from iptest import is_ironpython, generate_suite, run_test
2926
3027import {package}test.{name}
3128
3229def load_tests(loader, standard_tests, pattern):
33- if sys.implementation.name == 'ironpython':
34- suite = unittest.TestSuite()
35- {tests}
36- return suite
30+ tests = loader.loadTestsFromModule({package}test.{name}, pattern=pattern)
31+
32+ if is_ironpython:
33+ {tests}
34+
35+ failing_tests = []
36+
37+ skip_tests = []
38+
39+ return generate_suite(tests, failing_tests, skip_tests)
3740
3841 else:
39- return loader.loadTestsFromModule({package}test.{name}, pattern)
42+ return tests
4043
4144run_test(__name__)
4245"""
@@ -51,24 +54,34 @@ def load_tests(loader, standard_tests, pattern):
5154 sys .path .insert (0 , os .path .abspath (os .path .join (__file__ , "../../Src/StdLib/Lib" )))
5255 module = importlib .import_module ("{package}test.{name}" .format (name = name , package = package + "." if package else "" ))
5356
54- existing_tests = {}
55- try :
56- re_failure = re .compile (r'^\s*suite\.addTest\(unittest\.expectedFailure\((.*)\)\)( #.*)?$' )
57- re_ok = re .compile (r'^\s*suite\.addTest\((.*)\)( #.*)?$' )
58- with open (filepath , "r" , encoding = "utf-8" ) as f :
59- for line in f :
60- match = re_failure .match (line ) or re_ok .match (line )
61- if match :
62- existing_tests [match .group (1 )] = match .group (0 )
63- except FileNotFoundError :
64- pass
65-
6657 tests = []
6758 for suite in unittest .defaultTestLoader .loadTestsFromModule (module ):
6859 for test in suite :
6960 tests .append ("{}('{}')" .format (unittest .util .strclass (test .__class__ ), test ._testMethodName ))
7061
71- tests = [existing_tests .get (t , " suite.addTest({})" .format (t )) for t in tests ]
62+ if os .path .exists (filepath ):
63+ with open (filepath , "r" , encoding = "utf-8" ) as f :
64+ lines = list (f )
65+
66+ existing_tests = set ()
67+
68+ first = 0
69+ for i , line in enumerate (lines ):
70+ if "{" in line : raise NotImplementedError
71+
72+ if not first :
73+ if line .startswith (" if is_ironpython:" ):
74+ first = i + 1
75+ else :
76+ if line .startswith (" return generate_suite(" ):
77+ break
78+ existing_tests .add (line .split ("#" )[0 ].strip ().rstrip ("," ))
79+
80+ tests = [t for t in tests if t not in existing_tests ]
81+
82+ if tests :
83+ lines .insert (first , " {tests}\n " )
84+ template = "" .join (lines )
7285
7386 with open (filepath , "w" , encoding = "utf-8" ) as f :
74- f .write (template .format (name = name , package = package + "." if package else "" , tests = "\n " .join (tests )))
87+ f .write (template .format (name = name , package = package + "." if package else "" , tests = "\n " .join (tests )))
0 commit comments