def test_find_searches_in_default_locations(monkeypatch, tmp_nbs, root_path): root_path = Path(root_path).resolve() Path('subdir').mkdir() mock = Mock(wraps=dagspec.default.entry_point_with_name) monkeypatch.setattr(dagspec.default, 'entry_point_with_name', mock) DAGSpec.find(starting_dir=root_path) mock.assert_called_once_with(root_path=root_path, name=None)
def test_find(tmp_nbs, monkeypatch): mock = Mock(return_value=[None, None]) monkeypatch.setattr(dagspec.DAGSpec, '_auto_load', mock) env = {'a': 1} DAGSpec.find(env=env) mock.assert_called_once_with(to_dag=False, starting_dir=None, env={'a': 1}, lazy_import=False, reload=False)
def test_expand_built_in_placeholders(tmp_directory, monkeypatch): tmp_directory = Path(tmp_directory).resolve() Path('setup.py').touch() Path('src', 'pkg').mkdir(parents=True) Path('subdir').mkdir() def mockreturn(): return 'username' monkeypatch.setattr(expand.getpass, "getuser", mockreturn) spec_dict = { 'meta': { 'extract_product': False }, 'tasks': [{ 'source': str(Path('{{root}}', 'script.py')), 'product': { 'nb': str(Path('{{cwd}}', '{{user}}', 'nb.html')), 'data': str(Path('{{here}}', 'data.csv')), }, }] } Path('src', 'pkg', 'pipeline.yaml').write_text(yaml.dump(spec_dict)) os.chdir(Path('src', 'pkg')) spec = DAGSpec.find() assert spec.data['tasks'][0]['source'] == Path(tmp_directory, 'script.py') assert spec.data['tasks'][0]['product']['nb'] == str( Path(tmp_directory, 'src', 'pkg', 'username', 'nb.html')) assert spec.data['tasks'][0]['product']['data'] == str( Path(tmp_directory, 'src', 'pkg', 'data.csv'))
def test_load_spec_with_custom_name_in_packaged_structure(backup_test_pkg): os.chdir(Path(backup_test_pkg).parents[1]) path = Path('src', 'test_pkg') shutil.copy(path / 'pipeline.yaml', path / 'pipeline.serve.yaml') spec = DAGSpec.find(name='pipeline.serve.yaml') assert spec.path == (path / 'pipeline.serve.yaml').resolve()
def test_load_spec_with_custom_name(tmp_nbs): shutil.copy('pipeline.yaml', 'pipeline.serve.yaml') spec = DAGSpec.find(name='pipeline.serve.yaml') assert spec.path.resolve() == Path('pipeline.serve.yaml').resolve()