예제 #1
0
def fake_project_cli(
    fake_repo_path: Path, dummy_config: Path, fake_kedro_cli: click.CommandCollection
):
    old_settings = settings.as_dict()
    starter_path = Path(__file__).parents[3].resolve()
    starter_path = starter_path / "features" / "steps" / "test_starter"
    CliRunner().invoke(
        fake_kedro_cli, ["new", "-c", str(dummy_config), "--starter", str(starter_path)]
    )

    # NOTE: Here we load a couple of modules, as they would be imported in
    # the code and tests.
    # It's safe to remove the new entries from path due to the python
    # module caching mechanism. Any `reload` on it will not work though.
    old_path = sys.path.copy()
    sys.path = [str(fake_repo_path / "src")] + sys.path

    import_module(PACKAGE_NAME)
    configure_project(PACKAGE_NAME)
    yield fake_kedro_cli

    # reset side-effects of configure_project
    pipelines._clear(PACKAGE_NAME)  # this resets pipelines loading state
    for key, value in old_settings.items():
        settings.set(key, value)
    sys.path = old_path
    del sys.modules[PACKAGE_NAME]
예제 #2
0
def fake_project_cli(fake_repo_path: Path, dummy_config: Path):
    old_settings = settings.as_dict()
    starter_path = Path(__file__).parents[3].resolve()
    starter_path = starter_path / "features" / "steps" / "test_starter"
    # This is needed just for the tests, those CLI groups are merged in our
    # code when invoking `kedro` but when imported, they still need to be merged
    kedro_cli = click.CommandCollection(name="Kedro",
                                        sources=[cli, create_cli])
    CliRunner().invoke(
        kedro_cli,
        ["new", "-c",
         str(dummy_config), "--starter",
         str(starter_path)],
    )

    # NOTE: Here we load a couple of modules, as they would be imported in
    # the code and tests.
    # It's safe to remove the new entries from path due to the python
    # module caching mechanism. Any `reload` on it will not work though.
    old_path = sys.path.copy()
    sys.path = [str(fake_repo_path / "src")] + sys.path

    import_module(PACKAGE_NAME)
    configure_project(PACKAGE_NAME)
    yield import_module(f"{PACKAGE_NAME}.cli")

    # reset side-effects of configure_project
    pipelines.clear()
    for key, value in old_settings.items():
        settings.set(key, value)
    sys.path = old_path
    del sys.modules[PACKAGE_NAME]
예제 #3
0
def mock_package_name_with_settings_file(tmpdir):
    old_settings = settings.as_dict()
    settings_file_path = tmpdir.mkdir("test_package").join("settings.py")
    settings_file_path.write(
        textwrap.dedent(f"""
                from {__name__} import MOCK_CONTEXT_CLASS
                CONF_ROOT = "test_conf"
                CONTEXT_CLASS = MOCK_CONTEXT_CLASS
            """))
    project_path, package_name, _ = str(settings_file_path).rpartition(
        "test_package")
    sys.path.insert(0, project_path)
    yield package_name
    sys.path.pop(0)
    # reset side-effect of configure_project
    for key, value in old_settings.items():
        settings.set(key, value)