Skip to content

Commit e304fd1

Browse files
authored
Simplify _stdlib tests (#1634)
* Simplify _stdlib tests * Skip datetime tests * Re-enable test
1 parent b839d57 commit e304fd1

52 files changed

Lines changed: 1425 additions & 5871 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Src/IronPython/Lib/iptest/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# The .NET Foundation licenses this file to you under the Apache 2.0 License.
33
# See the LICENSE file in the project root for more information.
44

5-
from .ipunittest import IronPythonTestCase, stdout_trapper, stderr_trapper, path_modifier, retryOnFailure, run_test, skipUnlessIronPython, source_root, expectedFailureIf
5+
from .ipunittest import IronPythonTestCase, stdout_trapper, stderr_trapper, path_modifier, retryOnFailure, run_test, skipUnlessIronPython, source_root, expectedFailureIf, generate_suite
66
from .test_env import *
77
from .type_util import *
88
from .misc_util import ip_supported_encodings

Src/IronPython/Lib/iptest/ipunittest.py

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,9 @@ def load_ironpython_test(*args):
112112
clr.AddReference("Microsoft.Dynamic")
113113
clr.AddReference("IronPython")
114114

115-
if args:
115+
if args:
116116
return clr.LoadAssemblyFromFileWithPath(_iron_python_test_dll)
117-
else:
117+
else:
118118
clr.AddReferenceToFileAndPath(_iron_python_test_dll)
119119

120120
class IronPythonTestCase(unittest.TestCase, FileUtil, ProcessUtil):
@@ -195,6 +195,37 @@ def run_test(name):
195195
from test import support
196196
support.run_unittest(name)
197197

198+
def _flatten_suite(suite):
199+
tests = []
200+
for t in suite:
201+
if isinstance(t, unittest.BaseTestSuite):
202+
tests.extend(_flatten_suite(t))
203+
else:
204+
tests.append(t)
205+
return tests
206+
207+
def generate_suite(tests, failing_tests, skip_tests=[]):
208+
all_tests = _flatten_suite(tests)
209+
test_indices = {t: i for i, t in enumerate(all_tests)}
210+
unknown_tests = []
211+
212+
for t in skip_tests:
213+
try:
214+
all_tests[test_indices.pop(t)] = None
215+
except ValueError:
216+
unknown_tests.append(t)
217+
218+
for t in failing_tests:
219+
try:
220+
all_tests[test_indices.pop(t)] = unittest.expectedFailure(t)
221+
except ValueError:
222+
unknown_tests.append(t)
223+
224+
if unknown_tests:
225+
raise ValueError("Unknown tests:\n - {}".format('\n - '.join(str(t) for t in unknown_tests)))
226+
227+
return unittest.TestSuite(t for t in all_tests if t is not None)
228+
198229
# class testpath:
199230
# # find the ironpython root directory
200231
# rowan_root = get_environ_variable("dlr_root")
@@ -220,13 +251,13 @@ def run_test(name):
220251
# lib_testdir = path_combine(external_dir, '27/Lib')
221252
# private_testdir = path_combine(external_dir, '27/Lib/test')
222253

223-
# if is_cli:
254+
# if is_cli:
224255
# ipython_executable = sys.executable
225256
# if is_posix:
226257
# cpython_executable = '/usr/bin/python2.7'
227258
# else:
228259
# cpython_executable = path_combine(external_dir, '27/python.exe')
229-
# else:
260+
# else:
230261
# ipython_executable = path_combine(sys.prefix, 'ipy.exe')
231262
# cpython_executable = sys.executable
232263

Src/IronPythonTest/Cases/IronPythonCasesManifest.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ Timeout=300000 # 5 minute timeout - sometimes slow
108108
[IronPython.test_sqlite3_stdlib]
109109
IsolationLevel=PROCESS
110110
RunCondition=NOT $(IS_OSX) # https://github.com/IronLanguages/ironpython3/issues/1483
111+
NotParallelSafe=true
111112

112113
[IronPython.test_stdconsole]
113114
Timeout=600000 # 10 minute timeout

Src/StdLib/Lib/test/test_socket.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5632,7 +5632,9 @@ def test_new_tcp_flags(self):
56325632
self.assertEqual([], unknown,
56335633
"New TCP flags were discovered. See bpo-32394 for more information")
56345634

5635-
def test_main():
5635+
5636+
# ironpython: refactored to use load_tests protocol
5637+
def load_tests(*args):
56365638
tests = [GeneralModuleTests, BasicTCPTest, TCPCloserTest, TCPTimeoutTest,
56375639
TestExceptions, BufferIOTest, BasicTCPTest2, BasicUDPTest, UDPTimeoutTest ]
56385640

@@ -5689,8 +5691,11 @@ def test_main():
56895691
])
56905692
tests.append(TestMSWindowsTCPFlags)
56915693

5694+
return unittest.TestSuite([unittest.makeSuite(test) for test in tests])
5695+
5696+
def test_main():
56925697
thread_info = support.threading_setup()
5693-
support.run_unittest(*tests)
5698+
support.run_unittest(__name__)
56945699
support.threading_cleanup(*thread_info)
56955700

56965701
if __name__ == "__main__":

Tests/gen_stdlib_test.py

Lines changed: 36 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -22,21 +22,24 @@
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
3027
import {package}test.{name}
3128
3229
def 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
4144
run_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)))

Tests/modules/system_related/test_resource_stdlib.py

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,30 +6,23 @@
66
## Run selected tests from test_resource from StdLib
77
##
88

9-
import unittest
10-
import sys
11-
12-
from iptest import run_test
9+
from iptest import is_ironpython, generate_suite, run_test
1310

1411
import test.test_resource
1512

1613
def load_tests(loader, standard_tests, pattern):
17-
if sys.implementation.name == 'ironpython':
18-
suite = unittest.TestSuite()
19-
suite.addTest(test.test_resource.ResourceTest('test_args'))
20-
suite.addTest(test.test_resource.ResourceTest('test_freebsd_contants'))
21-
#suite.addTest(test.test_resource.ResourceTest('test_fsize_enforced')) # TODO: handle SIGXFSZ
22-
suite.addTest(test.test_resource.ResourceTest('test_fsize_ismax'))
23-
suite.addTest(test.test_resource.ResourceTest('test_fsize_toobig'))
24-
suite.addTest(test.test_resource.ResourceTest('test_getrusage'))
25-
suite.addTest(test.test_resource.ResourceTest('test_linux_constants'))
26-
suite.addTest(test.test_resource.ResourceTest('test_pagesize'))
27-
suite.addTest(test.test_resource.ResourceTest('test_prlimit'))
28-
suite.addTest(test.test_resource.ResourceTest('test_prlimit_refcount'))
29-
suite.addTest(test.test_resource.ResourceTest('test_setrusage_refcount'))
30-
return suite
14+
tests = loader.loadTestsFromModule(test.test_resource, pattern=pattern)
15+
16+
if is_ironpython:
17+
failing_tests = []
18+
19+
skip_tests = [
20+
test.test_resource.ResourceTest('test_fsize_enforced') # TODO: handle SIGXFSZ
21+
]
22+
23+
return generate_suite(tests, failing_tests, skip_tests)
3124

3225
else:
33-
return loader.loadTestsFromModule(test.test_resource, pattern)
26+
return tests
3427

3528
run_test(__name__)

Tests/modules/type_related/test_bitfields_ctypes_stdlib.py

Lines changed: 14 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -6,43 +6,25 @@
66
## Run selected tests from test_bitfields from StdLib
77
##
88

9-
import unittest
10-
import sys
11-
12-
from iptest import run_test
9+
from iptest import is_ironpython, generate_suite, run_test, is_windows
1310

1411
import ctypes.test.test_bitfields
1512

1613
def load_tests(loader, standard_tests, pattern):
17-
if sys.implementation.name == 'ironpython':
18-
suite = unittest.TestSuite()
19-
suite.addTest(ctypes.test.test_bitfields.BitFieldTest('test_anon_bitfields'))
20-
suite.addTest(ctypes.test.test_bitfields.BitFieldTest('test_c_wchar'))
21-
suite.addTest(ctypes.test.test_bitfields.BitFieldTest('test_longlong'))
22-
suite.addTest(ctypes.test.test_bitfields.BitFieldTest('test_mixed_2'))
23-
suite.addTest(ctypes.test.test_bitfields.BitFieldTest('test_mixed_3'))
24-
suite.addTest(ctypes.test.test_bitfields.BitFieldTest('test_multi_bitfields_size'))
25-
suite.addTest(ctypes.test.test_bitfields.BitFieldTest('test_nonint_types'))
26-
suite.addTest(ctypes.test.test_bitfields.BitFieldTest('test_signed'))
27-
suite.addTest(ctypes.test.test_bitfields.BitFieldTest('test_single_bitfield_size'))
28-
suite.addTest(ctypes.test.test_bitfields.BitFieldTest('test_uint32'))
29-
suite.addTest(ctypes.test.test_bitfields.BitFieldTest('test_uint32_swap_big_endian'))
30-
suite.addTest(ctypes.test.test_bitfields.BitFieldTest('test_uint32_swap_little_endian'))
31-
suite.addTest(ctypes.test.test_bitfields.BitFieldTest('test_uint64'))
32-
suite.addTest(ctypes.test.test_bitfields.BitFieldTest('test_ulonglong'))
33-
suite.addTest(ctypes.test.test_bitfields.BitFieldTest('test_unsigned'))
34-
suite.addTest(ctypes.test.test_bitfields.C_Test('test_ints'))
35-
if sys.platform.startswith('win'):
36-
suite.addTest(ctypes.test.test_bitfields.BitFieldTest('test_mixed_1'))
37-
suite.addTest(ctypes.test.test_bitfields.BitFieldTest('test_mixed_4'))
38-
suite.addTest(ctypes.test.test_bitfields.C_Test('test_shorts'))
39-
else: # https://github.com/IronLanguages/ironpython3/issues/1442
40-
suite.addTest(unittest.expectedFailure(ctypes.test.test_bitfields.BitFieldTest('test_mixed_1')))
41-
suite.addTest(unittest.expectedFailure(ctypes.test.test_bitfields.BitFieldTest('test_mixed_4')))
42-
suite.addTest(unittest.expectedFailure(ctypes.test.test_bitfields.C_Test('test_shorts')))
43-
return suite
14+
tests = loader.loadTestsFromModule(ctypes.test.test_bitfields, pattern=pattern)
15+
16+
if is_ironpython:
17+
failing_tests = []
18+
if not is_windows: # https://github.com/IronLanguages/ironpython3/issues/1442
19+
failing_tests += [
20+
ctypes.test.test_bitfields.BitFieldTest('test_mixed_1'),
21+
ctypes.test.test_bitfields.BitFieldTest('test_mixed_4'),
22+
ctypes.test.test_bitfields.C_Test('test_shorts'),
23+
]
24+
25+
return generate_suite(tests, failing_tests)
4426

4527
else:
46-
return loader.loadTestsFromModule(ctypes.test.test_bitfields, pattern)
28+
return tests
4729

4830
run_test(__name__)

Tests/test_abc_stdlib.py

Lines changed: 10 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -6,40 +6,21 @@
66
## Run selected tests from test_abc from StdLib
77
##
88

9-
import unittest
10-
import sys
11-
12-
from iptest import run_test
9+
from iptest import is_ironpython, generate_suite, run_test
1310

1411
import test.test_abc
1512

1613
def load_tests(loader, standard_tests, pattern):
17-
if sys.implementation.name == 'ironpython':
18-
suite = unittest.TestSuite()
19-
suite.addTest(test.test_abc.TestABC('test_ABC_helper'))
20-
suite.addTest(test.test_abc.TestABC('test_abstractclassmethod_basics'))
21-
suite.addTest(test.test_abc.TestABC('test_abstractmethod_basics'))
22-
suite.addTest(test.test_abc.TestABC('test_abstractmethod_integration'))
23-
suite.addTest(test.test_abc.TestABC('test_abstractproperty_basics'))
24-
suite.addTest(test.test_abc.TestABC('test_abstractstaticmethod_basics'))
25-
suite.addTest(test.test_abc.TestABC('test_all_new_methods_are_called'))
26-
suite.addTest(test.test_abc.TestABC('test_customdescriptors_with_abstractmethod'))
27-
suite.addTest(test.test_abc.TestABC('test_descriptors_with_abstractmethod'))
28-
suite.addTest(test.test_abc.TestABC('test_isinstance_invalidation'))
29-
suite.addTest(test.test_abc.TestABC('test_metaclass_abc'))
30-
suite.addTest(test.test_abc.TestABC('test_register_as_class_deco'))
31-
suite.addTest(test.test_abc.TestABC('test_register_non_class'))
32-
suite.addTest(test.test_abc.TestABC('test_registration_basics'))
33-
suite.addTest(test.test_abc.TestABC('test_registration_builtins'))
34-
suite.addTest(test.test_abc.TestABC('test_registration_edge_cases'))
35-
suite.addTest(test.test_abc.TestABC('test_registration_transitiveness'))
36-
suite.addTest(unittest.expectedFailure(test.test_abc.TestABCWithInitSubclass('test_works_with_init_subclass'))) # https://github.com/IronLanguages/ironpython3/issues/1448
37-
suite.addTest(test.test_abc.TestLegacyAPI('test_abstractclassmethod_basics'))
38-
suite.addTest(test.test_abc.TestLegacyAPI('test_abstractproperty_basics'))
39-
suite.addTest(test.test_abc.TestLegacyAPI('test_abstractstaticmethod_basics'))
40-
return suite
14+
tests = loader.loadTestsFromModule(test.test_abc, pattern=pattern)
15+
16+
if is_ironpython:
17+
failing_tests = [
18+
test.test_abc.TestABCWithInitSubclass('test_works_with_init_subclass'), # https://github.com/IronLanguages/ironpython3/issues/1448
19+
]
20+
21+
return generate_suite(tests, failing_tests)
4122

4223
else:
43-
return loader.loadTestsFromModule(test.test_abc, pattern)
24+
return tests
4425

4526
run_test(__name__)

0 commit comments

Comments
 (0)