Example #1
0
def test_two_datafiles(cmd_args, tmp_path, mocker, plot):
    """Mock two different runs. Need different values in parameters.txt
    to trigger particular test lines."""
    os.chdir(tmp_path)
    Path("realization-0").mkdir()
    Path("realization-1").mkdir()
    for filename in DATAFILE.parent.glob("*"):
        if not filename.is_dir():
            shutil.copy(filename, "realization-0/")
            shutil.copy(filename, "realization-1/")

    Path("realization-0/parameters.txt").write_text("FOO 1\nSAME 10",
                                                    encoding="utf8")
    Path("realization-1/parameters.txt").write_text("FOO 2\nSAME 10",
                                                    encoding="utf8")
    mocker.patch(
        "sys.argv",
        get_plot_cmds(plot) + cmd_args + [
            str(Path("realization-0") / DATAFILE.name),
            str(Path("realization-1") / DATAFILE.name),
        ],
    )
    summaryplot.main()
    if not plot:
        assert Path("summaryplotdump.png").exists()
        assert Path("summaryplotdump.pdf").exists()
Example #2
0
def test_warnings(cmd_args, match, tmp_path, mocker, caplog):
    """Run command line arguments that give warning"""
    os.chdir(tmp_path)
    mocker.patch("sys.argv", [SCRIPTNAME, "--dumpimages"] + cmd_args)
    summaryplot.main()
    assert match in caplog.text
    assert Path("summaryplotdump.png").exists()
    assert Path("summaryplotdump.pdf").exists()
Example #3
0
def test_sysexit(cmd_args, tmp_path, mocker):
    """Run command line arguments that should end in failure"""
    os.chdir(tmp_path)
    mocker.patch("sys.argv", [SCRIPTNAME, "--dumpimages"] + cmd_args)
    with pytest.raises(SystemExit):
        summaryplot.main()
    assert not Path("summaryplotdump.png").exists()
    assert not Path("summaryplotdump.pdf").exists()
Example #4
0
def test_summaryplotter(cmd_args, tmpdir, mocker):
    """Test multiple command line invocations"""
    tmpdir.chdir()
    mocker.patch(
        "sys.argv",
        ["summaryplot", "--dumpimages"] + cmd_args +
        [str(DATAFILE), str(DATAFILE)],
        # DATAFILE is repeated, or else colourby will not be triggered.
    )
    summaryplot.main()
    assert Path("summaryplotdump.png").exists()
    assert Path("summaryplotdump.pdf").exists()
Example #5
0
def test_summaryplotter(cmd_args, tmp_path, mocker, plot):
    """Test multiple command line invocations"""
    os.chdir(tmp_path)
    mocker.patch(
        "sys.argv",
        get_plot_cmds(plot) + cmd_args +
        [str(DATAFILE), str(DATAFILE)],
        # DATAFILE is repeated, or else colourby will not be triggered.
    )
    summaryplot.main()
    if not plot:
        assert Path("summaryplotdump.png").exists()
        assert Path("summaryplotdump.pdf").exists()