(self)
| 674 | ) |
| 675 | |
| 676 | def test_compare_modified_ast(self): |
| 677 | # The ast API is a bit underspecified. The objects are mutable, |
| 678 | # and even _fields and _attributes are mutable. The compare() does |
| 679 | # some simple things to accommodate mutability. |
| 680 | a = ast.parse("m * x + b", mode="eval") |
| 681 | b = ast.parse("m * x + b", mode="eval") |
| 682 | self.assertTrue(ast.compare(a, b)) |
| 683 | |
| 684 | a._fields = a._fields + ("spam",) |
| 685 | a.spam = "Spam" |
| 686 | self.assertNotEqual(a._fields, b._fields) |
| 687 | self.assertFalse(ast.compare(a, b)) |
| 688 | self.assertFalse(ast.compare(b, a)) |
| 689 | |
| 690 | b._fields = a._fields |
| 691 | b.spam = a.spam |
| 692 | self.assertTrue(ast.compare(a, b)) |
| 693 | self.assertTrue(ast.compare(b, a)) |
| 694 | |
| 695 | b._attributes = b._attributes + ("eggs",) |
| 696 | b.eggs = "eggs" |
| 697 | self.assertNotEqual(a._attributes, b._attributes) |
| 698 | self.assertFalse(ast.compare(a, b, compare_attributes=True)) |
| 699 | self.assertFalse(ast.compare(b, a, compare_attributes=True)) |
| 700 | |
| 701 | a._attributes = b._attributes |
| 702 | a.eggs = b.eggs |
| 703 | self.assertTrue(ast.compare(a, b, compare_attributes=True)) |
| 704 | self.assertTrue(ast.compare(b, a, compare_attributes=True)) |
| 705 | |
| 706 | def test_compare_literals(self): |
| 707 | constants = ( |
nothing calls this directly
no test coverage detected