コード例 #1
0
def test_should_raise_if_git_command_fail(work_dir, mocker):
    """
        Test a MlVTool message is raised if git command fail
    """
    mocker.patch('subprocess.check_output', side_effect=SubprocessError)
    with pytest.raises(MlVToolException) as e:
        get_git_top_dir(work_dir)
    assert isinstance(e.value.__cause__, SubprocessError)
コード例 #2
0
def test_should_return_git_top_dir(work_dir, mocker):
    """
        Test get git top dir call subprocess
    """
    mocked_check_output = mocker.patch('subprocess.check_output',
                                       return_value=b'/work_dir')
    assert get_git_top_dir(work_dir) == '/work_dir'
    assert mocked_check_output.mock_calls == [
        mocker.call(['git', 'rev-parse', '--show-toplevel'], cwd=work_dir)
    ]
コード例 #3
0
    def run(self, *args, **kwargs):
        args = ArgumentBuilder(formatter_class=argparse.ArgumentDefaultsHelpFormatter,
                               description='Export a DVC pipeline to sequential execution.') \
            .add_force_argument() \
            .add_work_dir_argument() \
            .add_argument('--dvc', type=str, required=True, help='DVC targeted pipeline metadata step') \
            .add_argument('-o', '--output', type=str, help='The Python pipeline script output path',
                          required=True) \
            .parse(args)

        self.set_log_level(args)

        work_dir = args.working_directory or get_git_top_dir(dirname(args.dvc))

        if not args.force and exists(args.output):
            raise MlVToolException(
                f'Output file {args.output} already exists, use --force option to overwrite it'
            )

        export_pipeline(args.dvc, args.output, work_dir)
コード例 #4
0
def get_work_directory(input_path: str) -> str:
    if not exists(input_path):
        raise MlVToolException(f'Input file {input_path} does not exist.')
    return get_git_top_dir(dirname(input_path))