Exemplo n.º 1
0
def test_empty_string():
    level = level_interval("")
    parameter = LevelParameter(level)
    assert parameter.value is None

    with pytest.raises(InvalidParameterValue) as exc:
        LevelParameter("")
    assert "Unable to parse the level values entered" in str(exc.value)
Exemplo n.º 2
0
def test_series_string_input():
    # one value
    parameter = LevelParameter("1000")
    assert parameter.value == [1000.0]
    # two values separated by ","
    parameter = LevelParameter("1000, 2000")
    assert parameter.value == [1000.0, 2000.0]
    # more than two values ...
    parameter = LevelParameter("1000, 2000, 3000")
    assert parameter.value == [1000.0, 2000.0, 3000.0]
Exemplo n.º 3
0
def test_interval_string_input():
    # start/
    parameter = LevelParameter("1000/")
    assert parameter.value == (1000, None)
    # /end
    parameter = LevelParameter("/2000")
    assert parameter.value == (None, 2000)
    # start/end
    parameter = LevelParameter("1000/2000")
    assert parameter.value == (1000, 2000)
Exemplo n.º 4
0
def test_level_series_input():
    value = [1000, 2000, 3000]
    vstring = ",".join([str(i) for i in value])

    for lev in (vstring, value, tuple(value)):

        level = level_series(lev)
        parameter = LevelParameter(level)
        assert parameter.type == "series"
        assert parameter.value == value
        assert parameter.asdict() == {"level_values": value}
Exemplo n.º 5
0
def test_validate_error_no_slash():
    level = "1000 2000"
    with pytest.raises(InvalidParameterValue) as exc:
        LevelParameter(level)
    assert (
        str(exc.value) == "LevelParameter should be passed in as a range separated by /"
    )
Exemplo n.º 6
0
def test_validate_error_len_1_tuple():
    level = (1000,)
    with pytest.raises(InvalidParameterValue) as exc:
        LevelParameter(level)
    assert (
        str(exc.value)
        == "LevelParameter should be a range. Expected 2 values, received 1"
    )
Exemplo n.º 7
0
def test__str__():
    level = level_interval("1000/2000")
    parameter = LevelParameter(level)
    assert (parameter.__str__() == "Level range to subset over"
            f"\n first_level: 1000.0"
            f"\n last_level: 2000.0")
    assert parameter.__repr__() == parameter.__str__()
    assert parameter.__unicode__() == parameter.__str__()
Exemplo n.º 8
0
def test__str__():
    level = "1000/2000"
    parameter = LevelParameter(level)
    assert (
        parameter.__str__() == "Level range to subset over"
        f"\n start: 1000.0"
        f"\n end: 2000.0"
    )
    assert parameter.__repr__() == parameter.__str__()
    assert parameter.__unicode__() == parameter.__str__()
Exemplo n.º 9
0
def test_float_string():
    level = level_interval("1000.50/2000.60")
    parameter = LevelParameter(level)
    assert parameter.value == (1000.5, 2000.6)
Exemplo n.º 10
0
def test_validate_error_format():
    level = 1000
    with pytest.raises(InvalidParameterValue) as exc:
        LevelParameter(level)
    assert str(exc.value) == "LevelParameter is not in an accepted format"
Exemplo n.º 11
0
def test_raw():
    level = "1000/2000"
    parameter = LevelParameter(level)
    assert parameter.raw == level
Exemplo n.º 12
0
def test_class_instance():
    level = "1000/2000"
    parameter = LevelParameter(level)
    new_parameter = LevelParameter(parameter)
    assert new_parameter.tuple == (1000, 2000)
Exemplo n.º 13
0
def test_class_instance():
    level = level_interval("1000/2000")
    parameter = LevelParameter(level)
    new_parameter = LevelParameter(parameter)
    assert new_parameter.value == (1000, 2000)
Exemplo n.º 14
0
def test_int_tuple():
    level = (1000, 2000)
    parameter = LevelParameter(level)
    assert parameter.tuple == (1000, 2000)
Exemplo n.º 15
0
def test_float_tuple():
    level = (1000.50, 2000.60)
    parameter = LevelParameter(level)
    assert parameter.tuple == (1000.5, 2000.6)
Exemplo n.º 16
0
def test_not_numbers():
    level = (datetime.datetime(2085, 1, 1), datetime.datetime(2120, 12, 30))
    with pytest.raises(InvalidParameterValue) as exc:
        LevelParameter(level)
    assert str(exc.value) == "Level values must be a number"
Exemplo n.º 17
0
def test_start_slash_end():
    level = level_interval("1000/2000")
    parameter = LevelParameter(level)
    assert parameter.value == (1000, 2000)
Exemplo n.º 18
0
def test_word_string():
    level = level_interval("level/range")
    with pytest.raises(InvalidParameterValue) as exc:
        LevelParameter(level)
    assert str(exc.value) == "Values must be valid numbers"
Exemplo n.º 19
0
def test_validate_error_format():
    level = 1000
    with pytest.raises(InvalidParameterValue) as exc:
        LevelParameter(level)
    assert "not allowed" in str(exc.value)
Exemplo n.º 20
0
def test_raw():
    level = level_interval("1000/2000")
    parameter = LevelParameter(level)
    assert parameter.raw == level
Exemplo n.º 21
0
def test_word_string():
    level = "level/range"
    with pytest.raises(InvalidParameterValue) as exc:
        LevelParameter(level)
    assert str(exc.value) == "Level values must be a number"
Exemplo n.º 22
0
def test_trailing_slash():
    level = "/2000"
    parameter = LevelParameter(level)
    assert parameter.tuple == (None, 2000)
Exemplo n.º 23
0
def test_tuple():
    level = "1000/2000"
    parameter = LevelParameter(level)
    assert parameter.tuple == (1000, 2000)
Exemplo n.º 24
0
def test_as_dict():
    level = "1000/2000"
    parameter = LevelParameter(level)
    assert parameter.asdict() == {"start": 1000, "end": 2000}
Exemplo n.º 25
0
def test_float_string():
    level = "1000.50/2000.60"
    parameter = LevelParameter(level)
    assert parameter.tuple == (1000.5, 2000.6)
Exemplo n.º 26
0
def test_slash_none():
    level = "/"
    parameter = LevelParameter(level)
    assert parameter.tuple == (None, None)
    assert parameter.asdict() == {"start": None, "end": None}
Exemplo n.º 27
0
def test_string_tuple():
    level = ("1000.50", "2000.60")
    parameter = LevelParameter(level)
    assert parameter.tuple == (1000.5, 2000.6)
Exemplo n.º 28
0
def test_none():
    level = None
    parameter = LevelParameter(level)
    assert parameter.tuple == (None, None)
Exemplo n.º 29
0
def test_starting_slash():
    level = "1000/"
    parameter = LevelParameter(level)
    assert parameter.tuple == (1000, None)
Exemplo n.º 30
0
def test_empty_string():
    level = ""
    parameter = LevelParameter(level)
    assert parameter.tuple == (None, None)