diff options
author | Antoine Pitrou <solipsis@pitrou.net> | 2014-04-28 11:07:06 (GMT) |
---|---|---|
committer | Antoine Pitrou <solipsis@pitrou.net> | 2014-04-28 11:07:06 (GMT) |
commit | 871dfc41d37b02a7af6eb03028edc6702f24fd1d (patch) | |
tree | a790ec67f992917b9c1cad2fc654105d77a5c5bb /Lib/test/test_sys.py | |
parent | 94ba146d11869288ab3def8c7426b3b36701416a (diff) | |
download | cpython-871dfc41d37b02a7af6eb03028edc6702f24fd1d.zip cpython-871dfc41d37b02a7af6eb03028edc6702f24fd1d.tar.gz cpython-871dfc41d37b02a7af6eb03028edc6702f24fd1d.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 5a9699f..a68ed08 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() |