Example #1
0
def test_repo_mode_data():
    assert create_repository_loading_mode_data(
        RepositoryTargetInfo(
            repository_yaml='foo.yaml',
            module_name=None,
            python_file=None,
            fn_name=None,
        )) == RepositoryLoadingModeData(
            mode=RepositoryTargetMode.YAML_FILE,
            data='foo.yaml',
        )

    assert create_repository_loading_mode_data(
        RepositoryTargetInfo(
            repository_yaml=None,
            module_name='foo',
            python_file=None,
            fn_name='define_bar_repo',
        )) == RepositoryLoadingModeData(mode=RepositoryTargetMode.MODULE,
                                        data=ModuleTargetFunction(
                                            module_name='foo',
                                            fn_name='define_bar_repo',
                                        ))

    assert create_repository_loading_mode_data(
        RepositoryTargetInfo(
            repository_yaml=None,
            module_name=None,
            python_file='foo.py',
            fn_name='define_bar_repo',
        )) == RepositoryLoadingModeData(mode=RepositoryTargetMode.FILE,
                                        data=FileTargetFunction(
                                            python_file='foo.py',
                                            fn_name='define_bar_repo',
                                        ))
Example #2
0
def get_module_target_function(info):
    check.inst_param(info, 'info', RepositoryTargetInfo)
    if info.repository_yaml:
        mode_data = create_repository_loading_mode_data(info)
        file_path = mode_data.data
        check.str_param(file_path, 'file_path')
        config = load_yaml_from_path(file_path)
        repository_config = check.dict_elem(config, 'repository')
        module_name = check.opt_str_elem(repository_config, 'module')
        fn_name = check.str_elem(repository_config, 'fn')
        if module_name:
            return ModuleTargetFunction(module_name=module_name,
                                        fn_name=fn_name)
        return None
    elif info.module_name and info.fn_name:
        return ModuleTargetFunction(module_name=info.module_name,
                                    fn_name=info.fn_name)
    elif info.python_file and info.fn_name:
        return None
    else:
        raise InvalidRepositoryLoadingComboError()
Example #3
0
def test_pipeline_module():
    mode_data = create_pipeline_loading_mode_data(
        PipelineTargetInfo(
            module_name='foo_module',
            fn_name='define_pipeline',
            pipeline_name=None,
            python_file=None,
            repository_yaml=None,
        ))

    assert mode_data == PipelineLoadingModeData(
        mode=PipelineTargetMode.PIPELINE_MODULE,
        data=ModuleTargetFunction(module_name='foo_module',
                                  fn_name='define_pipeline'),
    )
Example #4
0
def test_repository_module():
    mode_data = create_pipeline_loading_mode_data(
        PipelineTargetInfo(
            module_name='bar_module',
            pipeline_name='foo',
            python_file=None,
            fn_name='define_bar_repo',
            repository_yaml=None,
        ))

    assert mode_data == PipelineLoadingModeData(
        mode=PipelineTargetMode.REPOSITORY_MODULE,
        data=RepositoryModuleData(
            module_target_function=ModuleTargetFunction(
                module_name='bar_module', fn_name='define_bar_repo'),
            pipeline_name='foo',
        ),
    )