def test_map_map_handling_exception(tmpdir):
    dst_folder = str(tmpdir)
    path = str(tmpdir) + 'test.nc'
    cube = iris.load_cube('./tests/testdata/tos_nemo_all_mean_map.nc')
    cube.attributes['map_type'] = 'invalid type'
    iris.save(cube, path)
    map_object = po.PresentationObject(dst_folder, path)
    with pytest.raises(exceptions.InvalidMapTypeException):
        map_object.create_dict()
def test_timeseries_object(tmpdir):
    dst_folder = str(tmpdir)
    path = './tests/testdata/tos_nemo_global_mean_year_mean_timeseries.nc'
    cube = iris.load_cube(path)
    timeseries_object = po.PresentationObject(dst_folder, path)
    assert isinstance(timeseries_object.loader, po.TimeseriesLoader)
    result = timeseries_object.create_dict()
    expected_result = {
        'title': cube.attributes['title'],
        'path': './tos_nemo_global_mean_year_mean_timeseries.png',
        'comment': cube.attributes['comment'],
        'presentation_type': 'image',
    }
    assert result == expected_result
def test_scalar_object(tmpdir):
    src = ["test.yml", "test.yaml"]
    error_messages = [
        f"File not found! Ignoring {src[0]}",
        f"File not found! Ignoring {src[1]}",
    ]
    for src, msg in zip(src, error_messages):
        with pytest.raises(exceptions.PresentationException, match=msg):
            po.ScalarLoader(src).load()

    src = str(tmpdir) + "/test.yml"
    dct = {"foo": "bar", "eggs": "ham"}
    with open(src, 'w') as file:
        yaml.dump(dct, file)
    scalar_object = po.PresentationObject("", src)
    assert isinstance(scalar_object.loader, po.ScalarLoader)
    result = scalar_object.create_dict()
    assert result == {'presentation_type': 'text', **dct}
def test_temporalmap_object(tmpdir, monkeypatch):
    path = './tests/testdata/tos_nemo_year_mean_temporalmap.nc'
    dst_folder = str(tmpdir)

    def mockreturn(*args, **kwargs):
        return plt.figure()

    temporalmap_object = po.PresentationObject(dst_folder, path)
    assert isinstance(temporalmap_object.loader, po.TemporalmapLoader)

    monkeypatch.setattr("helpers.map_type_handling.global_ocean_plot",
                        mockreturn)
    result = temporalmap_object.create_dict()
    cube = iris.load_cube(path)
    expected_result = {
        'title': cube.attributes['title'],
        'path': './tos_nemo_year_mean_temporalmap.gif',
        'comment': cube.attributes['comment'],
        'presentation_type': 'image',
    }
    assert result == expected_result