Пример #1
0
 def test_astdiff(self):
     src1 = textwrap.dedent("""
     a: int
     b: str""").lstrip()
     src2 = textwrap.dedent("""
     a: int
     b: float""").lstrip()
     tree1 = parser.parse_string(src1, python_version=self.python_version)
     tree2 = parser.parse_string(src2, python_version=self.python_version)
     normalize = lambda diff: textwrap.dedent("\n".join(diff))
     self.assertEqual(normalize(pytd_utils.ASTdiff(tree1, tree1)), src1)
     self.assertEqual(normalize(pytd_utils.ASTdiff(tree2, tree2)), src2)
     diff_pattern = r"(?s)- b.*\+ b"
     six.assertRegex(self, normalize(pytd_utils.ASTdiff(tree1, tree2)),
                     diff_pattern)
     six.assertRegex(self, normalize(pytd_utils.ASTdiff(tree2, tree1)),
                     diff_pattern)
Пример #2
0
 def testASTdiff(self):
   src1 = textwrap.dedent("""\
       a: int
       b: str""")
   src2 = textwrap.dedent("""\
       a: int
       b: float""")
   tree1 = parser.parse_string(src1, python_version=self.PYTHON_VERSION)
   tree2 = parser.parse_string(src2, python_version=self.PYTHON_VERSION)
   normalize = lambda diff: textwrap.dedent("\n".join(diff))
   self.assertEqual(normalize(pytd_utils.ASTdiff(tree1, tree1)), src1)
   self.assertEqual(normalize(pytd_utils.ASTdiff(tree2, tree2)), src2)
   diff_pattern = r"(?s)- b.*\+ b"
   self.assertRegexpMatches(normalize(pytd_utils.ASTdiff(tree1, tree2)),
                            diff_pattern)
   self.assertRegexpMatches(normalize(pytd_utils.ASTdiff(tree2, tree1)),
                            diff_pattern)