def test_simple_commands(script_runner: ScriptRunner, docker_from: str, local_repo_dir: Path): stdin = io.StringIO('true\n') ret = script_runner.run('bldr', 'shell', docker_from, '--local-repo-dir', local_repo_dir, stdin=stdin) assert ret.success, "`true` command should be succeded" assert ret.stderr == '', "nothing should be written to stderr" stdin = io.StringIO('false\n') ret = script_runner.run('bldr', 'shell', docker_from, '--local-repo-dir', local_repo_dir, stdin=stdin) assert not ret.success, "`false` command should be failed" assert ret.stderr == '', "nothing should be written to stderr" stdin = io.StringIO('exit 255\n') ret = script_runner.run('bldr', 'shell', docker_from, '--local-repo-dir', local_repo_dir, stdin=stdin) assert ret.returncode == 255, "exit code inside the container should be forwarded to the cli" assert ret.stderr == '', "nothing should be written to stderr"
def test_http_proxy(script_runner: ScriptRunner, docker_from: str, local_repo_dir: Path): env = dict(os.environ) env.update({'http_proxy': 'http://proxyurl.example:1234'}) stdin = io.StringIO('env\n') ret = script_runner.run('bldr', 'shell', docker_from, '--local-repo-dir', local_repo_dir, stdin=stdin, env=env) assert ret.success, "`env` command should be succeded" assert 'http_proxy=http://proxyurl.example:1234' in ret.stdout, "The shell command should pass the http_proxy env var" assert ret.stderr == '', "nothing should be written to stderr" stdin = io.StringIO('sudo env\n') ret = script_runner.run('bldr', 'shell', docker_from, '--local-repo-dir', local_repo_dir, stdin=stdin, env=env) assert ret.success, "`env` command as supersuer should be succeded" assert 'http_proxy=http://proxyurl.example:1234' in ret.stdout, "The env var 'http_proxy' should survive 'sudo'" assert ret.stderr == '', "nothing should be written to stderr"
def test_train_parse( raw_text: pathlib.Path, script_runner: pytest_console_scripts.ScriptRunner, tmp_path: pathlib.Path, train_config: pathlib.Path, treebank: pathlib.Path, ): ret = script_runner.run( "hopsparser", "train", str(train_config), str(treebank), str(tmp_path), "--dev-file", str(treebank), "--test-file", str(treebank), ) assert ret.success ret = script_runner.run( "hopsparser", "parse", str(tmp_path / "model"), str(treebank), str(tmp_path / f"{treebank.stem}.parsed2.conllu"), ) assert ret.success assert filecmp.cmp( tmp_path / f"{treebank.stem}.parsed.conllu", tmp_path / f"{treebank.stem}.parsed2.conllu", shallow=False, ) ret = script_runner.run( "hopsparser", "parse", "--raw", str(tmp_path / "model"), str(raw_text), str(tmp_path / f"{raw_text.stem}.parsed.conllu"), ) assert ret.success ret = script_runner.run( "hopsparser", "parse", str(tmp_path / "model"), str(tmp_path / f"{raw_text.stem}.parsed.conllu"), str(tmp_path / f"{raw_text.stem}.reparsed.conllu"), ) assert ret.success assert filecmp.cmp( str(tmp_path / f"{raw_text.stem}.parsed.conllu"), str(tmp_path / f"{raw_text.stem}.reparsed.conllu"), shallow=False, )
def test_item_search(self, script_runner: ScriptRunner): args = [ "stac-client", "search", "--url", ASTRAEA_URL, "-c", "naip", "--max-items", "20" ] result = script_runner.run(*args, print_result=False) assert result.success
def test_plot_npy(self, script_runner: ScriptRunner, tmp_path: Path) -> None: """Test plot subcommand with NumPy input file. GIVEN a data file WHEN invoking the plot subcommand THEN saves a plotted image to disk Parameters ---------- script_runner : ScriptRunner Command-line runner tmp_path : Path Temporary directory """ outfile = tmp_path.joinpath("projection.png") logfile = tmp_path.joinpath("plot.log") result = script_runner.run( "qaa", "plot", "-i", PROJNP, "-o", outfile.as_posix(), "-l", logfile.as_posix(), "--pca", "--verbose", ) assert result.success assert logfile.exists() assert outfile.exists() assert outfile.stat().st_size > 0
def test_no_cluster(self, script_runner: ScriptRunner, tmp_path: Path) -> None: """Test plot subcommand with CSV input file. GIVEN a data file WHEN invoking the plot subcommand with cluster option THEN saves a plotted image to disk Parameters ---------- script_runner : ScriptRunner Command-line runner tmp_path : Path Temporary directory """ outfile = tmp_path.joinpath("pca-cluster.png") logfile = tmp_path.joinpath("plot.log") result = script_runner.run( "qaa", "plot", "-i", CLUSTER, "-c", CENTROID, "-o", outfile.as_posix(), "-l", logfile.as_posix(), "--pca", "--verbose", ) assert result.success assert logfile.exists() assert outfile.exists() assert outfile.stat().st_size > 0
def test_plot_error(self, script_runner: ScriptRunner, tmp_path: Path) -> None: """Test plot subcommand with non-existent file. GIVEN a non-existent data file WHEN invoking the plot subcommand THEN an error is thrown Parameters ---------- script_runner : ScriptRunner Command-line runner tmp_path : Path Temporary directory """ outfile = tmp_path.joinpath("projection.png") logfile = tmp_path.joinpath("plot.log") result = script_runner.run( "qaa", "plot", "-i", "test.csv", "-o", outfile.as_posix(), "-l", logfile.as_posix(), "--pca", "--verbose", ) assert not result.success assert not logfile.exists() assert not outfile.exists()
def test_align(self, script_runner: ScriptRunner, tmp_path: Path) -> None: """Test align subcommand. GIVEN a trajectory file WHEN invoking the align subcommand THEN an aligned trajectory and average structure file will be written Parameters ---------- script_runner : ScriptRunner Command-line runner tmp_path : Path Temporary directory """ logfile = tmp_path.joinpath("align.log") result = script_runner.run( "qaa", "align", "-s", TOPWW, "-f", TRJWW, "-r", tmp_path.joinpath("average.pdb").as_posix(), "-o", tmp_path.joinpath("align.nc").as_posix(), "-l", logfile.as_posix(), "-m", "ca", ) assert result.success assert logfile.exists()
def test_cluster_npy(self, script_runner: ScriptRunner, tmp_path: Path) -> None: """Test cluster subcommand with binary Numpy input file. GIVEN a data file WHEN invoking the cluster subcommand THEN saves a cluster image to disk Parameters ---------- script_runner : ScriptRunner Command-line runner tmp_path : Path Temporary directory """ logfile = tmp_path.joinpath("cluster.log") result = script_runner.run( "qaa", "cluster", "-s", TOPWW, "-f", TRJWW, "-i", PROJNP, "-o", tmp_path.as_posix(), "-l", logfile.as_posix(), "--verbose", ) assert result.success assert logfile.exists()
def test_config_with_a_non_existent_file(script_runner: ScriptRunner, tmp_path: Path): config = tmp_path.joinpath('non-existent-config.json') ret = script_runner.run('bldr', '--config', str(config), 'build', 'ubuntu:bionic') assert not ret.success assert "Unable to open configuration file: '{}'".format( config) in ret.stderr
def test_config_with_a_non_json_file(script_runner: ScriptRunner, tmp_path: Path): config = tmp_path.joinpath('non-existent-config.json') config.write_text('{"foo": ') ret = script_runner.run('bldr', '--config', str(config), 'build', 'ubuntu:bionic') assert not ret.success assert "Unable to parse configuration file: 'Expecting value: line 1 column 9 (char 8)'" in ret.stderr
def test_gold_evaluation(script_runner: pytest_console_scripts.ScriptRunner, treebank: pathlib.Path): ret = script_runner.run( "eval_parse", "-v", str(treebank), str(treebank), ) assert ret.success
def test_who_am_i_should_the_outside_user(script_runner: ScriptRunner, docker_from: str, local_repo_dir: Path): stdin = io.StringIO('whoami\n') ret = script_runner.run('bldr', 'shell', docker_from, '--local-repo-dir', local_repo_dir, stdin=stdin) assert ret.success, "`whoami` command should be succeded" assert getpass.getuser() == ret.stdout.strip().split( '\n')[-1], "outside user should be inside" assert ret.stderr == '', "nothing should be written to stderr"
def test_build_dependencies_should_be_installed(script_runner: ScriptRunner, asset_dir: Path, docker_from: str, local_repo_dir: Path): stdin = io.StringIO('dpkg -l libblkid1\n') ret = script_runner.run('bldr', 'shell', docker_from, '--local-repo-dir', local_repo_dir, stdin=stdin, cwd=asset_dir.joinpath('example')) assert ret.success, "libblkid1 should be installed inside the shell, because it is a build dependency of e2fsprogs." assert ret.stderr == '', "nothing should be written to stderr"
def test_main_version(self, script_runner: ScriptRunner) -> None: """Test version option. GIVEN the main command-line interface WHEN the '--version' argument is provided THEN the version should print to the screen Parameters ---------- script_runner : ScriptRunner Command-line runner """ result = script_runner.run("qaa", "--version") assert qaa.__version__ in result.stdout
def test_main_help(self, script_runner: ScriptRunner) -> None: """Test help option. GIVEN the main command-line interface WHEN the '-h' or '--help' argument is provided THEN the help screen should appear Parameters ---------- script_runner : ScriptRunner Command-line runner """ result = script_runner.run( "qaa", "-h", ) result2 = script_runner.run( "qaa", "--help", ) assert "Usage:" in result.stdout assert result.success assert result.stdout == result2.stdout
def test_reindex(script_runner: ScriptRunner, asset_dir: Path, reindex_data: Path, tmp_path: Path, docker_from: str): ret = script_runner.run('bldr', 'reindex', docker_from, '--local-repo-dir', reindex_data) assert ret.success, "reindex command should be succeded" assert ret.stderr == '', "nothing should be written to stderr" expected_packages_content = asset_dir.joinpath( 'test-reindex-data', 'Packages.correct').read_text() assert reindex_data.joinpath('Packages').read_text( ) == expected_packages_content, 'Generated Packages file should be identical to Packages.correct' expected_sources_content = asset_dir.joinpath( 'test-reindex-data', 'Sources.correct').read_text() assert reindex_data.joinpath('Sources').read_text( ) == expected_sources_content, 'Generated Sources file should be identical to Sources.correct'
def test_command_help(script_runner: ScriptRunner): ret = script_runner.run('bldr', 'build', '--help') assert ret.success argument_list = [ 'docker_from', 'package', '--snapshot', '--shell', '--deb-build-options', '--local-repo-dir', '--nocache', '--container-env', '--hooks-dir', ] for argument in argument_list: assert argument in ret.stdout
def test_pca(self, script_runner: ScriptRunner, tmp_path: Path) -> None: """Test pca subcommand. GIVEN a trajectory file WHEN invoking the pca subcommand THEN an several files will be written Parameters ---------- script_runner : ScriptRunner Command-line runner tmp_path : Path Temporary directory """ logfile = tmp_path.joinpath("pca.log") result = script_runner.run( "qaa", "pca", "-s", TOPWW, "-f", TRJWW, "-o", tmp_path.as_posix(), "-l", logfile.as_posix(), "-m", "ca", "--verbose", ) assert result.success assert logfile.exists() # Test whether text data file exists data = tmp_path.joinpath("projection.csv") assert data.exists() assert data.stat().st_size > 0 # Test whether binary data file exists bin_data = tmp_path.joinpath("projection.npy") assert bin_data.exists() assert bin_data.stat().st_size > 0 assert tmp_path.joinpath("explained_variance_ratio.png").exists()
def test_help(self, script_runner: ScriptRunner) -> None: """Test help output. GIVEN the cluster subcommand WHEN the help option is invoked THEN the help output should be displayed Parameters ---------- script_runner : ScriptRunner Command-line runner """ result = script_runner.run( "qaa", "plot", "-h", ) assert result.success
def test_graph_parser( train_config: pathlib.Path, treebank: pathlib.Path, script_runner: pytest_console_scripts.ScriptRunner, tmp_path: pathlib.Path, ): ret = script_runner.run( "graph_parser", str(train_config), "--train_file", str(treebank), "--dev_file", str(treebank), "--pred_file", str(treebank), "--out_dir", str(tmp_path), ) assert ret.success
def test_failed_build(script_runner: ScriptRunner, asset_dir: Path, docker_from: str, local_repo_dir: Path): ret = script_runner.run('bldr', 'build', docker_from, "--local-repo-dir", str(local_repo_dir), cwd=asset_dir.joinpath('never-builds')) assert not ret.success, "build command should be failed" assert ret.stderr == '', "nothing should be written to stderr" assert local_repo_dir.joinpath( "Packages").is_file(), "Packages file should exist" assert local_repo_dir.joinpath( "Sources").is_file(), "Sources file should exist" assert local_repo_dir.joinpath( "Packages").stat().st_size == 0, "Packages file should be empty" assert local_repo_dir.joinpath( "Sources").stat().st_size == 0, "Sources file should be empty"
def test_build(script_runner: ScriptRunner, asset_dir: Path, docker_from: str, local_repo_dir: Path): ret = script_runner.run('bldr', 'build', docker_from, "--local-repo-dir", str(local_repo_dir), cwd=asset_dir.joinpath('example-lang-C')) assert ret.success, "build command should be succeded" assert 'Your deb files are at' in ret.stdout assert ret.stderr == '', "nothing should be written to stderr" assert local_repo_dir.joinpath( "Packages").is_file(), "Packages file should exist" assert local_repo_dir.joinpath( "Sources").is_file(), "Packages file should exist" assert local_repo_dir.joinpath( "Packages").stat().st_size > 0, "Packages file should be non-empty" assert local_repo_dir.joinpath( "Sources").stat().st_size > 0, "Sources file should be non-empty"
def test_cluster_save(self, script_runner: ScriptRunner, tmp_path: Path) -> None: """Test save option. GIVEN trajectory, topology and data files WHEN the '--save' option is provided THEN PDB files will be saved Parameters ---------- script_runner : ScriptRunner Command-line runner tmp_path : Path Temporary directory """ logfile = tmp_path.joinpath("cluster.log") result = script_runner.run( "qaa", "cluster", "-s", TOPWW, "-f", TRJWW, "-i", PROJ, "-o", tmp_path.as_posix(), "-l", logfile.as_posix(), "--pca", "--save", "--verbose", ) assert result.success assert logfile.exists() assert len(tuple(tmp_path.glob("*.pdb"))) == 3
def test_no_arguments(self, script_runner: ScriptRunner): args = ["stac-client"] result = script_runner.run(*args, print_result=False) assert result.success
def test_selftest(script_runner: ScriptRunner): ret = script_runner.run('bldr', 'selftest') assert ret.success, "selftest command should be succeded" assert ret.stderr == '', "nothing should be written to stderr"
def test_command_names_in_help(script_runner: ScriptRunner): ret = script_runner.run('bldr', '--help') assert ret.success for command_name in ['build', 'shell', 'reindex', 'selftest']: assert command_name in ret.stdout
def test_version(script_runner: ScriptRunner): ret = script_runner.run('bldr', '--version') assert ret.success, "version print should be succeded" assert ret.stdout == 'bldr {}\n'.format(get_version()) assert ret.stderr == '', "nothing should be written to stderr"