MCPcopy Index your code
hub / github.com/RustPython/RustPython / test_intern

Method test_intern

Lib/test/test_sys.py:756–786  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

754 self.assertEqual(sys.__stdout__.encoding, sys.__stderr__.encoding)
755
756 def test_intern(self):
757 has_is_interned = (test.support.check_impl_detail(cpython=True)
758 or hasattr(sys, '_is_interned'))
759 self.assertRaises(TypeError, sys.intern)
760 self.assertRaises(TypeError, sys.intern, b'abc')
761 if has_is_interned:
762 self.assertRaises(TypeError, sys._is_interned)
763 self.assertRaises(TypeError, sys._is_interned, b'abc')
764 s = "never interned before" + str(random.randrange(0, 10**9))
765 self.assertTrue(sys.intern(s) is s)
766 if has_is_interned:
767 self.assertIs(sys._is_interned(s), True)
768 s2 = s.swapcase().swapcase()
769 if has_is_interned:
770 self.assertIs(sys._is_interned(s2), False)
771 self.assertTrue(sys.intern(s2) is s)
772 if has_is_interned:
773 self.assertIs(sys._is_interned(s2), False)
774
775 # Subclasses of string can't be interned, because they
776 # provide too much opportunity for insane things to happen.
777 # We don't want them in the interned dict and if they aren't
778 # actually interned, we don't want to create the appearance
779 # that they are by allowing intern() to succeed.
780 class S(str):
781 def __hash__(self):
782 return 123
783
784 self.assertRaises(TypeError, sys.intern, S("abc"))
785 if has_is_interned:
786 self.assertIs(sys._is_interned(S("abc")), False)
787
788 @support.cpython_only
789 @requires_subinterpreters

Callers

nothing calls this directly

Calls 9

hasattrFunction · 0.85
strFunction · 0.85
randrangeMethod · 0.80
assertTrueMethod · 0.80
internMethod · 0.80
SClass · 0.70
assertRaisesMethod · 0.45
assertIsMethod · 0.45
swapcaseMethod · 0.45

Tested by

no test coverage detected