summaryrefslogtreecommitdiff
path: root/Lib/test
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2014-04-28 13:07:06 +0200
committerAntoine Pitrou <solipsis@pitrou.net>2014-04-28 13:07:06 +0200
commit871dfc41d37b02a7af6eb03028edc6702f24fd1d (patch)
treea790ec67f992917b9c1cad2fc654105d77a5c5bb /Lib/test
parent94ba146d11869288ab3def8c7426b3b36701416a (diff)
downloadcpython-git-871dfc41d37b02a7af6eb03028edc6702f24fd1d.tar.gz
Issue #13204: Calling sys.flags.__new__ would crash the interpreter, now it raises a TypeError.
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_sys.py20
1 files changed, 20 insertions, 0 deletions
diff --git a/Lib/test/test_sys.py b/Lib/test/test_sys.py
index 5a9699ff20..a68ed08df7 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()