MCPcopy Index your code
hub / github.com/python/cpython / test_compare_literals

Method test_compare_literals

Lib/test/test_ast/test_ast.py:706–748  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

704 self.assertTrue(ast.compare(b, a, compare_attributes=True))
705
706 def test_compare_literals(self):
707 constants = (
708 -20,
709 20,
710 20.0,
711 1,
712 1.0,
713 True,
714 0,
715 False,
716 frozenset(),
717 tuple(),
718 "ABCD",
719 "abcd",
720 "中文字",
721 1e1000,
722 -1e1000,
723 )
724 for next_index, constant in enumerate(constants[:-1], 1):
725 next_constant = constants[next_index]
726 with self.subTest(literal=constant, next_literal=next_constant):
727 self.assertTrue(
728 ast.compare(ast.Constant(constant), ast.Constant(constant))
729 )
730 self.assertFalse(
731 ast.compare(
732 ast.Constant(constant), ast.Constant(next_constant)
733 )
734 )
735
736 same_looking_literal_cases = [
737 {1, 1.0, True, 1 + 0j},
738 {0, 0.0, False, 0 + 0j},
739 ]
740 for same_looking_literals in same_looking_literal_cases:
741 for literal in same_looking_literals:
742 for same_looking_literal in same_looking_literals - {literal}:
743 self.assertFalse(
744 ast.compare(
745 ast.Constant(literal),
746 ast.Constant(same_looking_literal),
747 )
748 )
749
750 def test_compare_fieldless(self):
751 self.assertTrue(ast.compare(ast.Add(), ast.Add()))

Callers

nothing calls this directly

Calls 5

enumerateFunction · 0.85
assertTrueMethod · 0.80
assertFalseMethod · 0.80
subTestMethod · 0.45
compareMethod · 0.45

Tested by

no test coverage detected