diff options
author | Antoine Pitrou <solipsis@pitrou.net> | 2014-04-28 11:08:28 (GMT) |
---|---|---|
committer | Antoine Pitrou <solipsis@pitrou.net> | 2014-04-28 11:08:28 (GMT) |
commit | 3a74ce2088e5e29d81dd672038aef7204c82947b (patch) | |
tree | e0554959db9899de773aad8c1d004f50e35f6d28 /Lib/test/test_sys.py | |
parent | 6cd08d627723f122bc964f7da0d41c3ff439c509 (diff) | |
parent | 871dfc41d37b02a7af6eb03028edc6702f24fd1d (diff) | |
download | cpython-3a74ce2088e5e29d81dd672038aef7204c82947b.zip cpython-3a74ce2088e5e29d81dd672038aef7204c82947b.tar.gz cpython-3a74ce2088e5e29d81dd672038aef7204c82947b.tar.bz2 |
Issue #13204: Calling sys.flags.__new__ would crash the interpreter, now it raises a TypeError.
Diffstat (limited to 'Lib/test/test_sys.py')
-rw-r--r-- | Lib/test/test_sys.py | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/Lib/test/test_sys.py b/Lib/test/test_sys.py index a809fd7..4eadd4b 100644 --- a/Lib/test/test_sys.py +++ b/Lib/test/test_sys.py @@ -519,6 +519,26 @@ class SysModuleTest(unittest.TestCase): self.assertTrue(repr(sys.flags)) self.assertEqual(len(sys.flags), len(attrs)) + def assert_raise_on_new_sys_type(self, sys_attr): + # Users are intentionally prevented from creating new instances of + # sys.flags, sys.version_info, and sys.getwindowsversion. + attr_type = type(sys_attr) + with self.assertRaises(TypeError): + attr_type() + with self.assertRaises(TypeError): + attr_type.__new__(attr_type) + + def test_sys_flags_no_instantiation(self): + self.assert_raise_on_new_sys_type(sys.flags) + + def test_sys_version_info_no_instantiation(self): + self.assert_raise_on_new_sys_type(sys.version_info) + + def test_sys_getwindowsversion_no_instantiation(self): + # Skip if not being run on Windows. + test.support.get_attribute(sys, "getwindowsversion") + self.assert_raise_on_new_sys_type(sys.getwindowsversion()) + def test_clear_type_cache(self): sys._clear_type_cache() |