def test_from_import(self): node = ast.parse('from foo import bar') visitor = dependencies.DependencyVisitor() visitor.visit(node) # bar can be a module as well, so we need to assume it is. # A later step will filter it if it is not a module. self.assertEqual(['foo', 'foo.bar'], visitor.modules)
def test_function_call_keyword_not_found(self): node = ast.parse('open(x="foo.txt")') visitor = dependencies.DependencyVisitor(functions=[('*open', 'y', None)]) visitor.visit(node) self.assertEqual([], visitor.filenames)
def test_function_call_approx(self): node = ast.parse('gzip.gzopen("foo.gz", "w")') visitor = dependencies.DependencyVisitor(functions=[('*open', 0, None)]) visitor.visit(node) self.assertEqual(['foo.gz'], visitor.filenames)
def test_function_call_exact(self): node = ast.parse('open("foo.txt", "w")') visitor = dependencies.DependencyVisitor(functions=[('*open', 0, None)]) visitor.visit(node) self.assertEqual(['foo.txt'], visitor.filenames)
def test_function_call_arg_not_string(self): node = ast.parse('open(filename, "w")') visitor = dependencies.DependencyVisitor(functions=[('*open', 0, None)]) visitor.visit(node) self.assertEqual([], visitor.filenames)
def test_import(self): node = ast.parse('import foo as bar') visitor = dependencies.DependencyVisitor() visitor.visit(node) self.assertEqual(['foo'], visitor.modules)
def test_absolute_import(self): node = ast.parse( 'from __future__ import unicode_string, absolute_import') visitor = dependencies.DependencyVisitor() visitor.visit(node) self.assertTrue(visitor.absolute_import)