def test_cli_download_tutorials(files_dir, config): option_out = "--out={}".format(files_dir) nboption_src = "--src={}".format(config["notebook"]) scoption_src = "--src={}".format(config["script"]) option_release = "--release={}".format(config["release"]) dsdirname = "datasets" nbdirname = "notebooks-{}".format(config["release"]) scdirname = "scripts-{}".format(config["release"]) nbfilename = "{}.ipynb".format(config["notebook"]) scfilename = "{}.py".format(config["script"]) args = ["download", "tutorials", nboption_src, option_out, option_release] result = run_cli(cli, args) assert (Path(files_dir) / config["envfilename"]).exists() assert (Path(files_dir) / nbdirname / nbfilename).exists() # assert (Path(files_dir) / nbdirname / "images" / config["imagefile"]).exists() assert (Path(files_dir) / dsdirname / config["dataset"]).exists() assert "GAMMAPY_DATA" in result.output assert "jupyter lab" in result.output args = ["download", "tutorials", scoption_src, option_out, option_release] result = run_cli(cli, args) assert (Path(files_dir) / config["envfilename"]).exists() assert (Path(files_dir) / scdirname / scfilename).exists() assert "GAMMAPY_DATA" in result.output assert "jupyter lab" in result.output
def test_cli_download_tutorials(tmp_path, config): option_out = f"--out={tmp_path}" nboption_src = f"--src={config['notebook']}" scoption_src = f"--src={config['script']}" option_release = f"--release={config['release']}" dsdirname = "datasets" nbdirname = f"notebooks-{config['release']}" scdirname = f"scripts-{config['release']}" nbfilename = f"{config['notebook']}.ipynb" scfilename = f"{config['script']}.py" args = ["download", "tutorials", nboption_src, option_out, option_release] result = run_cli(cli, args) assert (tmp_path / config["envfilename"]).exists() assert (tmp_path / nbdirname / nbfilename).exists() assert (tmp_path / dsdirname / config["dataset"]).exists() assert "GAMMAPY_DATA" in result.output assert "jupyter lab" in result.output args = ["download", "tutorials", scoption_src, option_out, option_release] result = run_cli(cli, args) assert (tmp_path / config["envfilename"]).exists() assert (tmp_path / scdirname / scfilename).exists() assert "GAMMAPY_DATA" in result.output assert "jupyter lab" in result.output
def test_cli_download_notebooks(tmp_path, config): args = [ "download", "notebooks", f"--out={tmp_path}", f"--release={config['release']}", ] run_cli(cli, args) assert (tmp_path / config["release"] / config["envfilename"]).exists() assert (tmp_path / config["release"] / "tutorials" / "starting" / f"{config['notebook']}.ipynb").exists()
def test_cli_download_scripts(files_dir, config): option_out = "--out={}".format(files_dir) option_src = "--src={}".format(config["script"]) option_release = "--release={}".format(config["release"]) filename = "{}.py".format(config["script"]) dirname = "scripts-{}".format(config["release"]) args = ["download", "scripts", option_src, option_out, option_release] run_cli(cli, args) assert (Path(files_dir) / config["envfilename"]).exists() assert (Path(files_dir) / dirname / filename).exists()
def test_cli_download_scripts(tmp_path, config): args = [ "download", "scripts", f"--src={config['script']}", f"--out={tmp_path}", f"--release={config['release']}", ] run_cli(cli, args) assert (tmp_path / config["envfilename"]).exists() assert (tmp_path / f"scripts-{config['release']}/{config['script']}.py").exists()
def test_cli_download_notebooks(files_dir, config): option_out = "--out={}".format(files_dir) option_src = "--src={}".format(config["notebook"]) option_release = "--release={}".format(config["release"]) filename = "{}.ipynb".format(config["notebook"]) dirname = "notebooks-{}".format(config["release"]) args = ["download", "notebooks", option_src, option_out, option_release] run_cli(cli, args) assert (Path(files_dir) / config["envfilename"]).exists() # assert (Path(files_dir) / dirname / "images" / config["imagefile"]).exists() assert (Path(files_dir) / dirname / filename).exists()
def test_cli_download_notebooks(tmp_path, config): args = [ "download", "notebooks", f"--src={config['notebook']}", f"--out={tmp_path}", f"--release={config['release']}", ] run_cli(cli, args) assert (tmp_path / config["envfilename"]).exists() path = tmp_path / f"notebooks-{config['release']}/{config['notebook']}.ipynb" assert path.exists()
def test_cli_analysis_run(tmp_path): path_config = tmp_path / "config.yaml" config = get_example_config("1d") config.write(path_config) path_datasets = tmp_path / "datasets" args = [ "analysis", "run", f"--filename={path_config}", f"--out={path_datasets}", "--overwrite", ] run_cli(cli, args) assert path_datasets.exists()
def test_bin_image_main(tmpdir): """Run ``gammapy-bin-image`` and compare result to ``ctskymap``. """ event_file = "$GAMMAPY_DATA/tests/irf/hess/pa/hess_events_023523.fits.gz" reference_file = "$GAMMAPY_DATA/tests/irf/hess/pa/ctskymap.fits.gz" out_file = str(tmpdir / "gammapy_ctskymap.fits.gz") args = ["image", "bin", event_file, reference_file, out_file] run_cli(cli, args) actual = Map.read(out_file) expected = Map.read(reference_file) assert_allclose(actual.data, expected.data) assert_wcs_allclose(actual.geom.wcs, expected.geom.wcs)
def test_cli_info_no_args(): # No arguments should print all infos result = run_cli(cli, ["info"]) assert "System" in result.output assert "Gammapy package" in result.output assert "Other packages" in result.output assert "Gammapy environment variables" in result.output
def test_cli_download_datasets(tmp_path, config): option_out = f"--out={tmp_path}" args = ["download", "datasets", option_out] result = run_cli(cli, args) assert tmp_path.exists() assert "GAMMAPY_DATA" in result.output
def test_cli_download_datasets(files_dir, config): option_out = "--out={}".format(files_dir) option_src = "--src={}".format(config["dataset"]) option_release = "--release={}".format(config["release"]) args = ["download", "datasets", option_src, option_out, option_release] result = run_cli(cli, args) assert (Path(files_dir) / config["dataset"]).exists() assert "GAMMAPY_DATA" in result.output
def test_cli_download_datasets(files_dir, config): args = [ "download", "datasets", f"--src={config['dataset']}", f"--out={files_dir}", f"--release={config['release']}", ] result = run_cli(cli, args) assert (Path(files_dir) / config["dataset"]).exists() assert "GAMMAPY_DATA" in result.output
def test_cli_download_datasets(tmp_path, config): args = [ "download", "datasets", f"--src={config['dataset']}", f"--out={tmp_path}", f"--release={config['release']}", ] result = run_cli(cli, args) assert (tmp_path / config["dataset"]).exists() assert "GAMMAPY_DATA" in result.output
def test_cli_analysis_config(tmp_path): path_config = tmp_path / "config.yaml" args = ["analysis", "config", f"--filename={path_config}"] run_cli(cli, args) assert path_config.exists()
def test_cli_download_help(): result = run_cli(cli, ["download", "--help"]) assert "Usage" in result.output
def test_check_logging(): result = run_cli(cli, ["check", "logging"]) assert "output" in result.output
def test_cli_version(): result = run_cli(cli, ["--version"]) assert f"gammapy version {__version__}" in result.output
def test_cli_no_args(): # No arguments should print help result = run_cli(cli, []) assert "Usage" in result.output
def test_cli_version(): result = run_cli(cli, ["--version"]) assert "gammapy version {}".format(__version__) in result.output
def test_cli_help(): result = run_cli(cli, ["--help"]) assert "Usage" in result.output