Ejemplo n.º 1
0
 def test_identical(self):
     assert (ps.pyff_statement(
         ast.parse("a = a + b"),
         ast.parse("a = a + b"),
         pi.ImportedNames(),
         pi.ImportedNames(),
     ) is None)
Ejemplo n.º 2
0
    def test_identical(self):
        # ast.parse gives us ast.Module
        old = self._make_summary("def function(): return os.path.join(lst)")
        new = self._make_summary("def function(): return os.path.join(lst)")

        assert pf.pyff_function(old, new, pi.ImportedNames(),
                                pi.ImportedNames()) is None
Ejemplo n.º 3
0
    def test_invalid(self):
        with pytest.raises(ValueError):
            pf.pyff_function_code(self.FUNCTION, self.KLASS,
                                  pi.ImportedNames(), pi.ImportedNames())

        with pytest.raises(ValueError):
            pf.pyff_function_code(self.KLASS, self.FUNKTION,
                                  pi.ImportedNames(), pi.ImportedNames())
Ejemplo n.º 4
0
    def test_namechange(self):
        # ast.parse gives us ast.Module
        old = self._make_summary("def function(): return os.path.join(lst)")
        new = self._make_summary("def funktion(): return os.path.join(lst)")

        pyfference = pf.pyff_function(old, new, pi.ImportedNames(),
                                      pi.ImportedNames())
        assert pyfference.name == "funktion"
        assert pyfference.old_name == "function"
Ejemplo n.º 5
0
    def test_external_names(self):
        change = ps.pyff_statement(
            ast.parse("p = path.join(lst)"),
            ast.parse("p = pathy.join(lst)"),
            pi.ImportedNames(),
            pi.ImportedNames(),
        )
        # alone, the statements are different
        assert change.semantically_different()

        another_change = ps.pyff_statement(
            ast.parse("p = path.join(lst)"),
            ast.parse("p = pathy.join(lst)"),
            parse_imports("from os import path"),
            parse_imports("from os import path as pathy"),
        )
        # with information about imports, we can deduce the statements are semantically equivalent
        assert not another_change.semantically_different()
Ejemplo n.º 6
0
    def test_dictionary(self):
        names = pi.ImportedNames()
        assert not names

        names.add_import(ast.Import(names=[ast.alias(name="os", asname=None)]))
        assert len(names) == 1
        assert "os" in names
        assert names["os"].name == "os"
        assert len(names["os"].node.names) == 1

        assert list(sorted(names)) == ["os"]
Ejemplo n.º 7
0
    def test_import(self):
        names = pi.ImportedNames()
        names.add_import(
            ast.Import(
                names=[ast.alias(name="os", asname=None), ast.alias(name="sys", asname=None)]
            )
        )
        names.add_import(ast.Import(names=[ast.alias(name="ast", asname=None)]))
        assert len(names) == 3
        assert "os" in names
        assert "sys" in names
        assert "ast" in names

        assert names["os"].node is names["sys"].node
        assert names["os"].node is not names["ast"].node
Ejemplo n.º 8
0
 def test_importfrom(self):
     names = pi.ImportedNames()
     names.add_importfrom(
         ast.ImportFrom(
             module="os",
             level=0,
             names=[ast.alias(name="path", asname=None), ast.alias(name="environ", asname=None)],
         )
     )
     names.add_importfrom(
         ast.ImportFrom(module="sys", level=0, names=[ast.alias(name="exit", asname=None)])
     )
     assert len(names) == 3
     assert "path" in names
     assert "environ" in names
     assert "exit" in names
     assert names["path"].node is names["environ"].node
     assert names["exit"].node is not names["path"].node
     assert names.from_modules == {"os", "sys"}
Ejemplo n.º 9
0
 def test_different(self):
     change = ps.pyff_statement(ast.parse("a = a + b"),
                                ast.parse("a = a - b"), pi.ImportedNames(),
                                pi.ImportedNames())
     assert change.semantically_different()
Ejemplo n.º 10
0
 def test_asname(self):
     names = pi.ImportedNames()
     names.add_import(ast.Import(names=[ast.alias(name="os.environ", asname="oe")]))
     assert len(names) == 1
     assert "oe" in names
Ejemplo n.º 11
0
 def test_namechange(self):
     pyfference = pf.pyff_function_code(self.FUNCTION, self.FUNKTION,
                                        pi.ImportedNames(),
                                        pi.ImportedNames())
     assert pyfference.name == "funktion"
     assert pyfference.old_name == "function"
Ejemplo n.º 12
0
 def test_identical(self):
     assert (pf.pyff_function_code(self.FUNCTION, self.FUNCTION,
                                   pi.ImportedNames(), pi.ImportedNames())
             is None)