예제 #1
0
파일: module.py 프로젝트: cliping/avocado
 def add_imported_symbol(self, statement):
     """
     Keeps track of symbol names and importable entities
     """
     for index, name in enumerate(statement.names):
         final_name = self._get_name_from_alias_statement(name)
         imported_symbol = ImportedSymbol.from_statement(
             statement, os.path.abspath(self.path), index)
         self.imported_symbols[final_name] = imported_symbol
예제 #2
0
 def _check_basic(self, input_module_path, input_symbol, input_statement):
     """Checks all but to_str(), returning the imported_symbol instance."""
     statement = ast.parse(input_statement).body[0]
     symbol = ImportedSymbol.get_symbol_from_statement(statement)
     msg = f'Expected symbol name "{input_symbol}", found "{symbol}"'
     self.assertEqual(symbol, input_symbol, msg)
     module_path = ImportedSymbol.get_module_path_from_statement(statement)
     msg = f'Expected module path "{input_module_path}", ' f'found "{module_path}"'
     self.assertEqual(module_path, input_module_path, msg)
     imported_symbol = ImportedSymbol(module_path, symbol)
     self.assertEqual(imported_symbol,
                      ImportedSymbol.from_statement(statement))
     return imported_symbol
예제 #3
0
 def test_compound_levels(self):
     statement = ast.parse("from .path.parent8 import Class8").body[0]
     importer = "/abs/fs/location/of/imports.py"
     symbol = ImportedSymbol.from_statement(statement, importer)
     self.assertEqual(symbol.get_parent_fs_path(), "/abs/fs/location/of")
예제 #4
0
 def test_compound(self):
     statement = ast.parse("from path import parent3").body[0]
     importer = "/abs/fs/location/of/imports.py"
     symbol = ImportedSymbol.from_statement(statement, importer)
     self.assertEqual(symbol.get_parent_fs_path(),
                      "/abs/fs/location/of/path")
예제 #5
0
 def test_same_from_statement(self):
     statement = ast.parse("from .test_bar import symbol").body[0]
     importer = "/abs/fs/location/of/selftests/unit/test_foo.py"
     symbol = ImportedSymbol.from_statement(statement, importer)
     self.assertEqual(symbol.get_relative_module_fs_path(),
                      "/abs/fs/location/of/selftests/unit")
예제 #6
0
 def test_symbol_noalias(self):
     statement = ast.parse("from os import path").body[0]
     imported_symbol = ImportedSymbol.from_statement(statement)
     self.assertEqual(imported_symbol.symbol, "path")
     self.assertEqual(imported_symbol.symbol_name, "path")
예제 #7
0
 def test_module_noalias(self):
     statement = ast.parse("import os").body[0]
     imported_symbol = ImportedSymbol.from_statement(statement)
     self.assertEqual(imported_symbol.module_path, "os")
     self.assertEqual(imported_symbol.module_name, "os")