Beispiel #1
0
def test_class_instance():
    coll = (
        "cmip5.output1.INM.inmcm4.rcp45.mon.ocean.Omon.r1i1p1.latest.zostoga,"
        "cmip5.output1.MPI-M.MPI-ESM-LR.rcp45.mon.ocean.Omon.r1i1p1.latest.zostoga"
    )
    parameter = CollectionParameter(coll)
    new_parameter = CollectionParameter(parameter)
    assert new_parameter.value == (
        "cmip5.output1.INM.inmcm4.rcp45.mon.ocean.Omon.r1i1p1.latest.zostoga",
        "cmip5.output1.MPI-M.MPI-ESM-LR.rcp45.mon.ocean.Omon.r1i1p1.latest.zostoga",
    )
Beispiel #2
0
def test_raw():
    coll = [
        "cmip5.output1.INM.inmcm4.rcp45.mon.ocean.Omon.r1i1p1.latest.zostoga",
        "cmip5.output1.MPI-M.MPI-ESM-LR.rcp45.mon.ocean.Omon.r1i1p1.latest.zostoga",
    ]
    parameter = CollectionParameter(coll)
    assert parameter.raw == coll
def test_validate_error_id():
    collection = [
        "cmip5.output1.INM.inmcm4.rcp45.mon.ocean.Omon.r1i1p1.latest.zostoga",
        2,
    ]

    with pytest.raises(InvalidParameterValue) as exc:
        CollectionParameter(collection)
    assert str(exc.value) == "Each id in a collection must be a string"
Beispiel #4
0
def test_validate_error_id():
    coll = [
        "cmip5.output1.INM.inmcm4.rcp45.mon.ocean.Omon.r1i1p1.latest.zostoga",
        2,
    ]

    with pytest.raises(InvalidParameterValue) as exc:
        CollectionParameter(coll)
    assert (str(exc.value) == "Each id in a collection must be a string or "
            "an instance of <class 'roocs_utils.utils.file_utils.FileMapper'>")
Beispiel #5
0
def test_whitespace():
    coll = (
        "cmip5.output1.INM.inmcm4.rcp45.mon.ocean.Omon.r1i1p1.latest.zostoga, "
        "cmip5.output1.MPI-M.MPI-ESM-LR.rcp45.mon.ocean.Omon.r1i1p1.latest.zostoga "
    )

    parameter = CollectionParameter(coll)
    assert parameter.value == (
        "cmip5.output1.INM.inmcm4.rcp45.mon.ocean.Omon.r1i1p1.latest.zostoga",
        "cmip5.output1.MPI-M.MPI-ESM-LR.rcp45.mon.ocean.Omon.r1i1p1.latest.zostoga",
    )
def test_string():
    collection = (
        "cmip5.output1.INM.inmcm4.rcp45.mon.ocean.Omon.r1i1p1.latest.zostoga,"
        "cmip5.output1.MPI-M.MPI-ESM-LR.rcp45.mon.ocean.Omon.r1i1p1.latest.zostoga"
    )

    parameter = CollectionParameter(collection)
    assert parameter.tuple == (
        "cmip5.output1.INM.inmcm4.rcp45.mon.ocean.Omon.r1i1p1.latest.zostoga",
        "cmip5.output1.MPI-M.MPI-ESM-LR.rcp45.mon.ocean.Omon.r1i1p1.latest.zostoga",
    )
def test__str__():
    collection = [
        "cmip5.output1.INM.inmcm4.rcp45.mon.ocean.Omon.r1i1p1.latest.zostoga",
        "cmip5.output1.MPI-M.MPI-ESM-LR.rcp45.mon.ocean.Omon.r1i1p1.latest.zostoga",
    ]
    parameter = CollectionParameter(collection)

    assert (
        parameter.__str__() == "Datasets to analyse:"
        "\ncmip5.output1.INM.inmcm4.rcp45.mon.ocean.Omon.r1i1p1.latest.zostoga"
        "\ncmip5.output1.MPI-M.MPI-ESM-LR.rcp45.mon.ocean.Omon.r1i1p1.latest.zostoga"
    )

    assert parameter.__repr__() == parameter.__str__()
    assert parameter.__unicode__() == parameter.__str__()
Beispiel #8
0
def test_empty_string():
    coll = ""
    with pytest.raises(MissingParameterValue) as exc:
        CollectionParameter(coll)
    assert str(exc.value) == "CollectionParameter must be provided"
Beispiel #9
0
def test_one_id():
    coll = "cmip5.output1.INM.inmcm4.rcp45.mon.ocean.Omon.r1i1p1.latest.zostoga"
    parameter = CollectionParameter(coll)
    assert parameter.value == (
        "cmip5.output1.INM.inmcm4.rcp45.mon.ocean.Omon.r1i1p1.latest.zostoga",
    )
Beispiel #10
0
def test_none():
    coll = None

    with pytest.raises(InvalidParameterValue) as exc:
        CollectionParameter(coll)
    assert str(exc.value) == type_error.format("class 'NoneType'")
def test_none():
    collection = None

    with pytest.raises(MissingParameterValue) as exc:
        CollectionParameter(collection)
    assert str(exc.value) == "CollectionParameter must be provided"