def svn_source_repo(tmp_path_factory: TempPathFactory) -> Tuple[str, str, str]: """Init an svn repo & working copy for a workflow source dir. The working copy has a flow.cylc file with uncommitted changes. This dir is reused by all tests requesting it in this module. Returns (source_dir_path, repository_UUID, repository_path) """ tmp_path: Path = tmp_path_factory.getbasetemp() repo = tmp_path.joinpath('svn_repo') subprocess.run( ['svnadmin', 'create', 'svn_repo'], cwd=tmp_path, check=True) uuid = subprocess.run( ['svnlook', 'uuid', repo], check=True, capture_output=True, text=True ).stdout.splitlines()[0] project_dir = tmp_path.joinpath('project') project_dir.mkdir() project_dir.joinpath('flow.cylc').write_text(BASIC_FLOW_1) subprocess.run( ['svn', 'import', project_dir, f'file://{repo}/project/trunk', '-m', '"Initial import"'], check=True) source_dir = tmp_path.joinpath('svn_working_copy') subprocess.run( ['svn', 'checkout', f'file://{repo}/project/trunk', source_dir], check=True) flow_file = source_dir.joinpath('flow.cylc') # Overwrite file to introduce uncommitted changes: flow_file.write_text(BASIC_FLOW_2) return (str(source_dir), uuid, str(repo))
def git_source_repo(tmp_path_factory: TempPathFactory) -> Tuple[str, str]: """Init a git repo for a workflow source dir. The repo has uncommitted changes. This dir is reused by all tests requesting it in this module. Returns (source_dir_path, commit_hash) """ source_dir: Path = tmp_path_factory.getbasetemp() / 'git_repo' source_dir.mkdir() subprocess.run(['git', 'init'], cwd=source_dir, check=True) flow_file = source_dir / 'flow.cylc' flow_file.write_text(BASIC_FLOW_1) subprocess.run(['git', 'add', '-A'], cwd=source_dir, check=True) subprocess.run( ['git', 'commit', '-am', '"Initial commit"'], cwd=source_dir, check=True, capture_output=True) # Overwrite file to introduce uncommitted changes: flow_file.write_text(BASIC_FLOW_2) # Also add new file: (source_dir / 'gandalf.md').touch() commit_sha = subprocess.run( ['git', 'rev-parse', 'HEAD'], cwd=source_dir, check=True, capture_output=True, text=True ).stdout.splitlines()[0] return (str(source_dir), commit_sha)
def test_tmpdir_factory( tmpdir_factory: TempdirFactory, tmp_path_factory: pytest.TempPathFactory, ) -> None: assert str(tmpdir_factory.getbasetemp()) == str( tmp_path_factory.getbasetemp()) dir = tmpdir_factory.mktemp("foo") assert dir.exists()
def tmp_path_factory( request: pytest.FixtureRequest, tmp_path_factory: pytest.TempPathFactory ) -> Iterator[pytest.TempPathFactory]: """Modified `tmpdir_factory` session fixture that will automatically cleanup after itself. """ yield tmp_path_factory if not request.config.getoption("--keep-tmpdir"): shutil.rmtree( tmp_path_factory.getbasetemp(), ignore_errors=True, )
def test_server(tmp_path_factory: TempPathFactory) -> Iterator[None]: pid_file: Optional[Path] = None proc: Optional[subprocess.Popen] = None try: if ENABLE_INTEGRATION: pid_file = tmp_path_factory.getbasetemp() / "delta-sharing-server.pid" proc = subprocess.Popen( [ "./build/sbt", ( "server/test:runMain io.delta.sharing.server.TestDeltaSharingServer " + str(pid_file) ), ], stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd="..", ) ready = threading.Event() def wait_for_server() -> None: for line in proc.stdout: print(line.decode("utf-8").strip()) if b"https://127.0.0.1:12345/" in line: ready.set() threading.Thread(target=wait_for_server, daemon=True).start() if not ready.wait(timeout=120): raise TimeoutError("the server didn't start in 120 seconds") yield finally: if ENABLE_INTEGRATION: if pid_file is not None and pid_file.exists(): pid = pid_file.read_text() subprocess.run(["kill", "-9", pid]) if proc is not None and proc.poll() is None: proc.kill()
def mod_tmp_run_dir(tmp_path_factory: pytest.TempPathFactory): """Module-scoped version of tmp_run_dir()""" tmp_path = tmp_path_factory.getbasetemp() with pytest.MonkeyPatch.context() as mp: return tmp_run_dir(tmp_path, mp)
def mod_tmp_src_dir(tmp_path_factory: pytest.TempPathFactory): """Module-scoped version of tmp_src_dir()""" tmp_path = tmp_path_factory.getbasetemp() return tmp_src_dir(tmp_path)