Ejemplo n.º 1
0
 def test_relative_path(self):
     cwd = os.getcwd()
     try:
         # do not try to get package beyond given relative path
         os.chdir(FOO.pkg.resolve())
         assert ['foo_a'] == PyModule('foo_a.py').fqn
     finally:
         os.chdir(cwd)
Ejemplo n.º 2
0
 def _get_pkg_modules(self, pkg_name, get_sub_folders=True):
     """get all package modules recursively
     :param pkg_name: (str) path to search for python modules
     :param get_sub_folders: (bool) search sub-folders even if they are
                             not python packages
     """
     pkg_glob = os.path.join(pkg_name, "*.py")
     this_modules = glob.glob(pkg_glob)
     for dirname, dirnames, filenames in os.walk(pkg_name):
         for subdirname in dirnames:
             sub_path = os.path.join(dirname, subdirname)
             if get_sub_folders or PyModule.is_pkg(sub_path):
                 this_modules.extend(self._get_pkg_modules(sub_path))
     return this_modules
Ejemplo n.º 3
0
def get_imports(module_path):
    module = PyModule(module_path)
    base_path = module.pkg_path().resolve()
    mset = ModuleSet(base_path.glob('**/*.py'))
    imports = mset.get_imports(module, return_fqn=True)
    return {'modules': list(sorted(imports))}
Ejemplo n.º 4
0
def get_imports(module_path):
    module = PyModule(module_path)
    base_path = module.pkg_path().resolve()
    mset = ModuleSet(base_path.glob('**/*.py'))
    imports = mset.get_imports(module, return_fqn=True)
    return {'modules': list(sorted(imports))}
Ejemplo n.º 5
0
 def test_pkg_path(self):
     assert sample_dir == PyModule(BAR).pkg_path()
     assert sample_dir == PyModule(SUB.a).pkg_path()
Ejemplo n.º 6
0
 def test_fqn(self):
     assert ['bar'] == PyModule(BAR).fqn
     assert ['foo', '__init__'] == PyModule(FOO.init).fqn
     assert ['foo', 'foo_a'] == PyModule(FOO.a).fqn
     assert ['foo', 'sub', 'sub_a'] == PyModule(SUB.a).fqn
Ejemplo n.º 7
0
 def test_is_pkg(self):
     assert True == PyModule.is_pkg(FOO.pkg)
     assert False == PyModule.is_pkg(FOO.init)
     assert False == PyModule.is_pkg(FOO.a)
     assert True == PyModule.is_pkg(SUB.pkg)
     assert False == PyModule.is_pkg(SUB.a)
Ejemplo n.º 8
0
 def test_repr(self):
     module = PyModule(SUB.a)
     assert "<PyModule {}>".format(SUB.a) == repr(module)