Exemple #1
0
def test_root_dir():
    with MAGICC6() as magicc:
        m2 = MAGICC6(root_dir=magicc.root_dir)

        assert m2.root_dir == magicc.root_dir

        # Does nothing
        m2.remove_temp_copy()
        # Can be called many times
        m2.remove_temp_copy()

        assert m2.root_dir is not None
Exemple #2
0
def test_read_parameters():
    with MAGICC6() as magicc:
        # parameters don't exist
        with pytest.raises(FileNotFoundError):
            magicc.read_parameters()

        # Don't read config if it doesn't exist
        magicc.set_config(out_parameters=0)
        magicc.run()

        assert magicc.config is None

    with MAGICC6() as magicc:
        magicc.run()
        assert isinstance(magicc.config, dict)
        assert "allcfgs" in magicc.config
Exemple #3
0
def test_override_config():
    config["EXECUTABLE_6"] = "/tmp/magicc"
    magicc = MAGICC6()

    # Stop this override impacting other tests
    del config.overrides["EXECUTABLE_6"]
    assert magicc.executable == "/tmp/magicc"
Exemple #4
0
def test_missing_config(config_override):
    with MAGICC6():
        pass
    config_override("EXECUTABLE_6", "")
    with pytest.raises(FileNotFoundError):
        with MAGICC6():
            pass

    config_override("EXECUTABLE_6", "/invalid/path")
    with pytest.raises(FileNotFoundError):
        with MAGICC6():
            pass

    config_override("EXECUTABLE_7", "")
    with pytest.raises(FileNotFoundError):
        with MAGICC7():
            pass
Exemple #5
0
def test_incorrect_subdir():
    config["EXECUTABLE_6"] = "/tmp/magicc"
    magicc = MAGICC6()
    try:
        with pytest.raises(FileNotFoundError):
            magicc.create_copy()
    finally:
        del config.overrides["EXECUTABLE_6"]
        magicc.remove_temp_copy()
Exemple #6
0
def test_dont_create_dir():
    magicc = MAGICC6()
    # Dir isn't created yet
    assert magicc.root_dir is None
    magicc.create_copy()
    root_dir = magicc.root_dir
    assert exists(root_dir)
    magicc.remove_temp_copy()
    assert not exists(root_dir)
    assert magicc.root_dir is None
Exemple #7
0
def test_get_output_filenames(mock_listdir):
    mock_listdir.return_value = [
        'DAT_SLR_SEMIEMPI_RATE.OUT', 'DAT_SLR_SEMIEMPI_RATE.BINOUT',
        'TEMP_OCEANLAYERS.BINOUT', 'TEMP_OCEANLAYERS.OUT',
        'DAT_SLR_AIS_SMB.OUT', 'EXTRA.OTHER', 'PARAMETERS.OUT'
    ]

    m = MAGICC6()
    obs = sorted(m._get_output_filenames())
    exp = sorted([
        'DAT_SLR_SEMIEMPI_RATE.BINOUT', 'DAT_SLR_AIS_SMB.OUT',
        'TEMP_OCEANLAYERS.OUT', 'EXTRA.OTHER'
    ])
    np.testing.assert_array_equal(obs, exp)
Exemple #8
0
    def read(self, filepath=None, filename=None):
        """
        Read an input file from disk

        # Parameters
        filepath (str): The directory to file the file from. This is often the
            run directory for a magicc instance. If None is passed,
            the run directory for the bundled version of MAGICC6 is used.
        filename (str): The filename to read. Overrides any existing values.
        """
        if filepath is None:
            filepath = MAGICC6().original_dir
        if filename is not None:
            self.name = filename
        assert self.name is not None

        filename = join(filepath, self.name)
        if not exists(filename):
            raise ValueError("Cannot find {}".format(filename))

        reader = _get_reader(filename)
        self.metadata, self.df = reader.read()
Exemple #9
0
def test_not_initalise():
    p = MAGICC6()
    assert p.root_dir is None
    assert p.run_dir is None
    assert p.out_dir is None
Exemple #10
0
def test_no_root_dir():
    assert not exists("/tmp/magicc/")
    magicc = MAGICC6(root_dir="/tmp/magicc/")

    with pytest.raises(FileNotFoundError):
        magicc.run()