Beispiel #1
0
def test_get_inherited_classes():
    temp_folder = utils.make_tmpdir()
    pkg_name = 'pike_mgr_inherited_classes'
    pkg_location = utils.create_working_package(temp_folder, pkg_name)

    test_file_content = textwrap.dedent("""
    class SampleObj(object):
        pass

    class OtherObj(SampleObj):
        pass
    """)

    mod_location = os.path.join(pkg_location, 'app.py')
    utils.write_file(mod_location, test_file_content)

    # Include module directly on the search path
    second_file = textwrap.dedent("""
    class AnotherObj(object):
        pass
    """)
    mod_location = os.path.join(temp_folder, 'more.py')
    utils.write_file(mod_location, second_file)

    classes = []
    with PikeManager([temp_folder]) as mgr:
        app = py.get_module_by_name('{}.app'.format(pkg_name))
        classes = mgr.get_all_inherited_classes(app.SampleObj)

    assert len(classes) == 1
Beispiel #2
0
    def test_child_modules_without_sub_packages(self):
        mod_location = os.path.join(self.pkg_location, 'app.py')
        utils.write_file(mod_location)

        parent_module = py.get_module_by_name(self.pkg_name)
        child_modules = list(py._child_modules(parent_module))

        assert len(child_modules) == 1
Beispiel #3
0
    def setup_method(self, method):
        self.temp_folder = utils.make_tmpdir()

        # Create a simple package
        self.pkg_location = utils.create_working_package(
            self.temp_folder, 'compile_test')
        self.mod_location = os.path.join(self.pkg_location, 'app.py')
        utils.write_file(self.mod_location, SIMPLE_CLASS)

        py_compile.compile(self.mod_location)
Beispiel #4
0
    def setup_method(self, method):
        self.temp_folder = utils.make_tmpdir()

        # Create a simple package
        pkg_location = utils.create_working_package(self.temp_folder)
        mod_location = os.path.join(pkg_location, 'app.py')
        utils.write_file(mod_location, SIMPLE_CLASS)

        self.finder = PikeFinder([self.temp_folder])
        self.loader = PikeLoader('pike_tests.app', mod_location)
Beispiel #5
0
    def setup_method(self, method):
        super(TestDiscoverClasses, self).setup_method(method)
        self.test_file_content = textwrap.dedent("""
        class SampleObj(object):
            pass

        class OtherObj(SampleObj):
            pass
        """)

        mod_location = os.path.join(self.pkg_location, 'app.py')
        utils.write_file(mod_location, self.test_file_content)
Beispiel #6
0
    def test_recursive_find_modules(self):
        pkg_location = utils.create_working_package(self.temp_folder)
        subpkg_location = utils.create_working_package(pkg_location, 'bam')

        mod_location = os.path.join(pkg_location, 'app.py')
        utils.write_file(mod_location)
        mod_location = os.path.join(subpkg_location, 'other.py')
        utils.write_file(mod_location)

        pkgs = filesystem.recursive_find_modules(pkg_location)

        assert len(list(pkgs)) == 2
Beispiel #7
0
def compiled_loader():
    temp_folder = utils.make_tmpdir()

    # Create a simple package
    pkg_location = utils.create_working_package(temp_folder, 'compile_test')
    mod_location = os.path.join(pkg_location, 'app.py')
    utils.write_file(mod_location, SIMPLE_CLASS)

    py_compile.compile(mod_location)

    yield temp_folder

    utils.remove_dir(temp_folder)
Beispiel #8
0
def compiled_loader():
    temp_folder = utils.make_tmpdir()

    # Create a simple package
    pkg_location = utils.create_working_package(temp_folder, 'compile_test')
    mod_location = os.path.join(pkg_location, 'app.py')
    utils.write_file(mod_location, SIMPLE_CLASS)

    py_compile.compile(mod_location)

    yield temp_folder

    utils.remove_dir(temp_folder)
Beispiel #9
0
def loader_finder():
    temp_folder = utils.make_tmpdir()

    # Create a simple package
    pkg_location = utils.create_working_package(temp_folder)
    mod_location = os.path.join(pkg_location, 'app.py')
    utils.write_file(mod_location, SIMPLE_CLASS)

    finder = PikeFinder([temp_folder])
    loader = PikeLoader('pike_tests.app', mod_location)

    yield loader, finder

    utils.remove_dir(temp_folder)
Beispiel #10
0
def loader_finder():
    temp_folder = utils.make_tmpdir()

    # Create a simple package
    pkg_location = utils.create_working_package(temp_folder)
    mod_location = os.path.join(pkg_location, 'app.py')
    utils.write_file(mod_location, SIMPLE_CLASS)

    finder = PikeFinder([temp_folder])
    loader = PikeLoader('pike_tests.app', mod_location)

    yield loader, finder

    utils.remove_dir(temp_folder)
Beispiel #11
0
    def test_get_child_modules(self):
        subpkg_location = utils.create_working_package(
            self.pkg_location,
            'sub_mod'
        )
        mod_location = os.path.join(subpkg_location, 'something.py')
        utils.write_file(mod_location)

        module = py.get_module_by_name(self.pkg_name)
        # Recursive
        assert len(list(py.get_child_modules(module))) == 3

        # Non-Recursive
        assert len(list(py.get_child_modules(module, False))) == 2
Beispiel #12
0
    def test_child_modules_with_sub_packages(self):
        subpkg_location = utils.create_working_package(
            self.pkg_location,
            'submod'
        )

        mod_location = os.path.join(self.pkg_location, 'app.py')
        utils.write_file(mod_location)
        submod_location = os.path.join(subpkg_location, 'other.py')
        utils.write_file(submod_location)

        parent_module = py.get_module_by_name(self.pkg_name)
        child_modules = list(py._child_modules(parent_module))

        assert len(child_modules) == 2
Beispiel #13
0
    def test_import_from_path(self):
        mod_location = os.path.join(self.pkg_location, 'app.py')
        utils.write_file(mod_location)

        assert py._import_from_path(mod_location, self.pkg_name) is not None
Beispiel #14
0
    def test_find_modules(self):
        pkg_location = utils.create_working_package(self.temp_folder)
        mod_location = os.path.join(pkg_location, 'app.py')
        utils.write_file(mod_location)

        assert len(list(filesystem.find_modules(pkg_location))) == 1