def test_find_project_path(): with tempdir() as d: with pytest.raises(FileNotFoundError): assert find_project_path("foo", start=d, assert_exists=True) foo = d / "foo" with open(foo, "wt") as out: out.write("foo") assert find_project_path("foo", start=d, return_parent=False) == foo assert find_project_path("foo", start=d, return_parent=True) == d
def workflow_data_descriptor_file(project_root): """ Fixture that provides the path to the JSON file that describes test data files. """ return find_project_path("tests/test_bam/test_data.json", start=project_root, assert_exists=True)
def workflow_data_descriptor_file() -> Union[str, Path]: """ Fixture that provides the path to the JSON file that describes test data files. """ tests = find_project_path(Path("tests")) if tests: test_data = tests / DEFAULT_TEST_DATA_FILE if test_data.exists(): return test_data raise FileNotFoundError(f"Could not find {DEFAULT_TEST_DATA_FILE} file")
def workflow_data_descriptor_file(request: FixtureRequest) -> Union[str, Path]: """ Fixture that provides the path to the JSON file that describes test data files. Args: request: A FixtureRequest object """ return find_project_path(Path(DEFAULT_TEST_DATA_FILE), Path("tests") / DEFAULT_TEST_DATA_FILE, start=Path(request.fspath.dirpath()), assert_exists=True)
def project_root(request: FixtureRequest, project_root_files: List[str]) -> Union[str, Path]: """ Fixture that provides the root directory of the project. By default, this assumes that the project has one subdirectory per task, and that this framework is being run from the test subdirectory of a task diretory, and therefore looks for the project root two directories up. """ path = Path(request.fspath.dirpath()) root = find_project_path(*project_root_files, start=path, return_parent=True) if root: return root else: # If the project root can't be identified, fall back to the parent of # the current directory (which is probably tests). return path.parent
def import_dirs( request: FixtureRequest, project_root: Union[str, Path], import_paths: Optional[Union[str, Path]], ) -> List[Union[str, Path]]: """ Fixture that provides a list of directories containing WDL scripts to make avaialble as imports. Uses the file provided by `import_paths` fixture if it is not None, otherwise returns a list containing the parent directory of the test module. Args: request: A FixtureRequest object project_root: Project root directory import_paths: File listing paths to imports, one per line """ if import_paths: import_paths = ensure_path(import_paths, canonicalize=True) if not import_paths.exists(): raise FileNotFoundError( f"import_paths file {import_paths} does not exist") paths = [] with open(import_paths, "rt") as inp: for path_str in inp.read().splitlines(keepends=False): path = Path(path_str) if not path.is_absolute(): path = ensure_path(project_root / path) if not path.exists(): raise FileNotFoundError(f"Invalid import path: {path}") paths.append(path) return paths else: module_dir = find_project_path("tests", start=Path(request.fspath.dirpath()), return_parent=True) if module_dir: return [module_dir] else: return []
def workflow_data_descriptor_file(request: FixtureRequest) -> Union[str, Path]: """ Fixture that provides the path to the JSON file that describes test data files. Args: request: A FixtureRequest object """ test_data_files = [f"{DEFAULT_TEST_DATA_FILE}.json"] if yaml: test_data_files.append(f"{DEFAULT_TEST_DATA_FILE}.yaml") test_data_paths = [] for f in test_data_files: test_data_paths.extend((Path(f), Path("tests") / f)) return find_project_path(*test_data_files, start=Path(request.fspath.dirpath()), assert_exists=True)