diff options
author | Georg Brandl <georg@python.org> | 2006-12-19 20:50:34 (GMT) |
---|---|---|
committer | Georg Brandl <georg@python.org> | 2006-12-19 20:50:34 (GMT) |
commit | 66a796e5ab8dd7bfc1fe05a830feb05acdab6f53 (patch) | |
tree | 5ce191f813c475bf54c6ab40ecaebb820327a213 /Lib/test/test_sys.py | |
parent | 376446dd4e30006c4d4ad09b4cbda8b07e9ce23a (diff) | |
download | cpython-66a796e5ab8dd7bfc1fe05a830feb05acdab6f53.zip cpython-66a796e5ab8dd7bfc1fe05a830feb05acdab6f53.tar.gz cpython-66a796e5ab8dd7bfc1fe05a830feb05acdab6f53.tar.bz2 |
Patch #1601678: move intern() to sys.intern().
Diffstat (limited to 'Lib/test/test_sys.py')
-rw-r--r-- | Lib/test/test_sys.py | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/Lib/test/test_sys.py b/Lib/test/test_sys.py index f1f1524..fdeb500 100644 --- a/Lib/test/test_sys.py +++ b/Lib/test/test_sys.py @@ -350,6 +350,31 @@ class SysModuleTest(unittest.TestCase): # the test runs under regrtest. self.assert_(sys.__stdout__.encoding == sys.__stderr__.encoding) + def test_intern(self): + self.assertRaises(TypeError, sys.intern) + s = "never interned before" + self.assert_(sys.intern(s) is s) + s2 = s.swapcase().swapcase() + self.assert_(sys.intern(s2) is s) + + # Subclasses of string can't be interned, because they + # provide too much opportunity for insane things to happen. + # We don't want them in the interned dict and if they aren't + # actually interned, we don't want to create the appearance + # that they are by allowing intern() to succeeed. + class S(str): + def __hash__(self): + return 123 + + self.assertRaises(TypeError, sys.intern, S("abc")) + + # It's still safe to pass these strings to routines that + # call intern internally, e.g. PyObject_SetAttr(). + s = S("abc") + setattr(s, s, s) + self.assertEqual(getattr(s, s), s) + + def test_main(): test.test_support.run_unittest(SysModuleTest) |