def main() -> int: """Execute the main routine.""" parser = argparse.ArgumentParser() parser.add_argument("-r", "--release_dir", help="path to the release directory", required=True) parser.add_argument( "--operation_dir", help="path to the operation directory. If specified, you have to delete it yourself. " "Otherwise, uses mkdtemp and removes it at the end.") parser.add_argument( "--quiet", help="if specified, produces as little log messages as possible", action="store_true") args = parser.parse_args() params = params_from_command_line(args) tests.siger.Siger.initialize_signal_handlers() with temppathlib.TmpDirIfNecessary(path=params.operation_dir) as operation_dir: test_dir = operation_dir.path / 'test_{}'.format(uuid.uuid4()) test_dir.mkdir() run_test_control(release_dir=params.release_dir, operation_dir=test_dir / 'test_control', quiet=params.quiet) run_test_relay( release_dir=params.release_dir, operation_dir=operation_dir.path / 'test_relay', quiet=params.quiet) run_test_relay_errors( release_dir=params.release_dir, operation_dir=operation_dir.path / 'test_relay_errors', quiet=params.quiet) if not params.quiet: logthis.say("Test passed.") return 0
def run_entry_point( self, entry_point_name: str, param_file: Path, *, partition: str, working_directory: Path, # We deliberately don't set a default memory request because we want users # to think about if explicitly. memory_request: MemoryAmount, num_gpus: int = 0, num_cpus: int = 1, job_name: Optional[str] = None, slurm_script_path: Optional[Path] = None, echo_template: bool = False, ): slurm_script_directory = slurm_script_path.parent if slurm_script_path else None job_log_directory = self._job_log_directory(job_name) with temppathlib.TmpDirIfNecessary( path=slurm_script_directory) as tmp_dir: if not slurm_script_path: slurm_script_path = tmp_dir.path / f"{job_name}.sbatch" # Whether we use an account parameter or a quality of service parameter # depends on whether we are running on a project partition # or one of the available-to-everyone-but-you-can-be-killed-at-any-time partitions. if partition in ("scavenge", "ephemeral"): account_or_qos = f"#SBATCH --qos={partition}" else: account_or_qos = f"#SBATCH --account={partition}" slurm_template_content = SLURM_BATCH_TEMPLATE.format( partition=partition, account_or_qos=account_or_qos, job_name=job_name, memory_string=self._to_slurm_memory_string(memory_request), num_cpus=num_cpus, num_gpus=num_gpus, stdout_log_path=job_log_directory / f"{job_name}.log", spack_lines=self.spack_config.sbatch_lines() if self.spack_config else "", conda_lines=self.conda_config.sbatch_lines() if self.conda_config else "", working_directory=working_directory, entry_point=entry_point_name, param_file=param_file.absolute(), ) slurm_script_path.write_text( # type: ignore slurm_template_content, encoding="utf-8") if echo_template: print(slurm_template_content) subprocess.run( ["sbatch", str(slurm_script_path.absolute())], # type: ignore # Raise an exception on failure check=True, )
def test_with_path_str(self) -> None: basedir = pathlib.Path(tempfile.mkdtemp()) try: notmp_pth = str(basedir / "no-tmp") with temppathlib.TmpDirIfNecessary(path=notmp_pth) as maybe_tmp_dir: self.assertEqual(pathlib.Path(notmp_pth), maybe_tmp_dir.path) self.assertTrue(os.path.exists(notmp_pth)) finally: shutil.rmtree(str(basedir))
def main() -> None: """Execute the main routine.""" parser = argparse.ArgumentParser(description=__doc__) parser.add_argument( "--operation_dir", help="path to the directory where temporary test files are stored; " "if not specified, uses mkdtemp()") args = parser.parse_args() params = Params(args=args) cases_dir = tests.path.REPO_DIR / 'test_cases' ## # Check the environment ## if subprocess.call(['which', 'go'], stderr=subprocess.DEVNULL) != 0: raise RuntimeError( "Go compiler could not be found. Please make sure you installed it " "and put it on your PATH.") ## # Collect test cases ## schema_pths = sorted( list(cases_dir.glob("general/**/schema.json")) + list(cases_dir.glob("go/**/schema.json")) + list(cases_dir.glob("docs/**/schema.json"))) # yapf: disable cases = [ Case( schema_path=schema_pth, example_paths=sorted(schema_pth.parent.glob("example_*.json")), rel_path=schema_pth.parent.relative_to(cases_dir)) for schema_pth in schema_pths ] # yapf: enable with temppathlib.TmpDirIfNecessary( path=params.operation_dir) as base_operation_dir: ## # Execute the test cases ## for case in cases: execute_case(case=case, gopath=base_operation_dir.path / case.rel_path)
def test_with_base_tmp_dir(self) -> None: basedir = pathlib.Path(tempfile.mkdtemp()) try: tmp_pth = None # type: Optional[pathlib.Path] with temppathlib.TmpDirIfNecessary(path=None, base_tmp_dir=basedir) as maybe_tmp_dir: tmp_pth = maybe_tmp_dir.path self.assertTrue(tmp_pth.parent == basedir) self.assertFalse(tmp_pth.exists()) finally: shutil.rmtree(str(basedir))
def main() -> None: """Execute the main routine.""" parser = argparse.ArgumentParser(description=__doc__) parser.add_argument( "--operation_dir", help="path to the directory where temporary test files are stored; " "if not specified, uses mkdtemp()") args = parser.parse_args() params = Params(args=args) cases_dir = tests.path.REPO_DIR / 'test_cases' ## # Collect test cases ## schema_pths = sorted( list(cases_dir.glob("general/**/schema.json")) + list(cases_dir.glob("py/**/schema.json")) + list(cases_dir.glob("docs/**/schema.json"))) # yapf: disable cases = [ Case( schema_path=schema_pth, example_paths=sorted(schema_pth.parent.glob("example_*.json")), rel_path=schema_pth.parent.relative_to(cases_dir)) for schema_pth in schema_pths ] # yapf: enable with temppathlib.TmpDirIfNecessary( path=params.operation_dir) as base_operation_dir: ## # Execute the test cases ## src_dir = base_operation_dir.path / "src" src_dir.mkdir(exist_ok=True) for case in cases: execute_case(case=case, case_src_dir=src_dir / case.rel_path)
def main() -> int: """Execute the main routine.""" parser = argparse.ArgumentParser() parser.description = "CAUTION: This test will use real MailGun credits to send one email to the addresses you " \ "provide!" parser.add_argument("-r", "--release_dir", help="path to the release directory", required=True) parser.add_argument("--domain", help="name of the MailGun domain", required=True) parser.add_argument("--api_key_path", help="path to the MailGun API key", required=True) parser.add_argument( "--recipients", help="email addresses of the email recipients, separated by commas", required=True) parser.add_argument("--cc", help="email addresses for the email's cc field, separated by commas") parser.add_argument("--bcc", help="email addresses for the email's bcc field, separated by commas") parser.add_argument( "--database_dir", help="path to the database directory. If specified, you have to delete it yourself. " "Otherwise, uses mkdtemp and removes it at the end.") parser.add_argument( "--quiet", help="if specified, produces as little log messages as possible", action="store_true") args = parser.parse_args() params = params_from_command_line(args) tests.siger.Siger.initialize_signal_handlers() with temppathlib.TmpDirIfNecessary(path=params.database_dir) as database_dir: run(release_dir=params.release_dir, database_dir=database_dir.path, domain=params.domain, api_key_path=params.api_key_path, recipients=params.recipients, cc=params.cc, bcc=params.bcc, quiet=params.quiet) return 0
def main() -> int: """Execute the main routine.""" parser = argparse.ArgumentParser() parser.add_argument("-r", "--release_dir", help="path to the release directory", required=True) parser.add_argument( "--quiet", help="if specified, produces as little log messages as possible", action="store_true") args = parser.parse_args() assert isinstance(args.release_dir, str) assert isinstance(args.quiet, bool) release_dir = pathlib.Path(args.release_dir) tests.siger.Siger.initialize_signal_handlers() with temppathlib.TmpDirIfNecessary(path=None) as operation_dir: run_test(release_dir=release_dir, operation_dir=operation_dir.path, quiet=args.quiet) if not args.quiet: logthis.say("Test passed.") return 0
def test_prefix(self) -> None: with temppathlib.TmpDirIfNecessary(path=None, prefix="some_prefix") as tmp_dir: self.assertTrue(tmp_dir.path.name.startswith("some_prefix"))
def test_suffix(self) -> None: with temppathlib.TmpDirIfNecessary(path=None, suffix="some_suffix") as tmp_dir: self.assertTrue(tmp_dir.path.name.endswith("some_suffix"))