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

Method test_dont_merge_constants

Lib/test/test_compile.py:1003–1040  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

1001
1002 @unittest.expectedFailure # TODO: RUSTPYTHON; AssertionError: unable to find constant -0.0 in (0.0,)
1003 def test_dont_merge_constants(self):
1004 # Issue #25843: compile() must not merge constants which are equal
1005 # but have a different type.
1006
1007 def check_different_constants(const1, const2):
1008 ns = {}
1009 exec("f1, f2 = lambda: %r, lambda: %r" % (const1, const2), ns)
1010 f1 = ns['f1']
1011 f2 = ns['f2']
1012 self.assertIsNot(f1.__code__, f2.__code__)
1013 self.assertNotEqual(f1.__code__, f2.__code__)
1014 self.check_constant(f1, const1)
1015 self.check_constant(f2, const2)
1016 self.assertEqual(repr(f1()), repr(const1))
1017 self.assertEqual(repr(f2()), repr(const2))
1018
1019 check_different_constants(+0.0, -0.0)
1020 check_different_constants((0,), (0.0,))
1021 check_different_constants('a', b'a')
1022 check_different_constants(('a',), (b'a',))
1023
1024 # check_different_constants() cannot be used because repr(-0j) is
1025 # '(-0-0j)', but when '(-0-0j)' is evaluated to 0j: we loose the sign.
1026 f1, f2 = lambda: +0.0j, lambda: -0.0j
1027 self.assertIsNot(f1.__code__, f2.__code__)
1028 self.check_constant(f1, +0.0j)
1029 self.check_constant(f2, -0.0j)
1030 self.assertEqual(repr(f1()), repr(+0.0j))
1031 self.assertEqual(repr(f2()), repr(-0.0j))
1032
1033 # {0} is converted to a constant frozenset({0}) by the peephole
1034 # optimizer
1035 f1, f2 = lambda x: x in {0}, lambda x: x in {0.0}
1036 self.assertIsNot(f1.__code__, f2.__code__)
1037 self.check_constant(f1, frozenset({0}))
1038 self.check_constant(f2, frozenset({0.0}))
1039 self.assertTrue(f1(0))
1040 self.assertTrue(f2(0.0))
1041
1042 def test_path_like_objects(self):
1043 # An implicit test for PyUnicode_FSDecoder().

Callers

nothing calls this directly

Calls 7

check_constantMethod · 0.95
reprFunction · 0.85
assertIsNotMethod · 0.80
assertTrueMethod · 0.80
f1Function · 0.70
f2Function · 0.70
assertEqualMethod · 0.45

Tested by

no test coverage detected