예제 #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)
예제 #2
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__()
예제 #3
0
def test_validate_error_no_slash():
    with pytest.raises(InvalidParameterValue) as exc:
        level_interval("1000 2000")
    assert str(
        exc.value) == "Interval should be passed in as a range separated by /"
예제 #4
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"
예제 #5
0
def test_not_numbers():
    level = level_interval(datetime.datetime(2085, 1, 1),
                           datetime.datetime(2120, 12, 30))
    with pytest.raises(InvalidParameterValue) as exc:
        LevelParameter(level)
    assert str(exc.value) == "Values must be valid numbers"
예제 #6
0
def test_validate_error_len_1_tuple():
    with pytest.raises(InvalidParameterValue) as exc:
        level_interval((1000, ))
    assert str(exc.value
               ) == "Interval should be a range. Expected 2 values, received 1"
예제 #7
0
def test_raw():
    level = level_interval("1000/2000")
    parameter = LevelParameter(level)
    assert parameter.raw == level
예제 #8
0
def test_string_tuple():
    level = level_interval("1000.50", "2000.60")
    parameter = LevelParameter(level)
    assert parameter.value == (1000.5, 2000.6)
예제 #9
0
def test_white_space():
    level = level_interval(" 1000 /2000")
    parameter = LevelParameter(level)
    assert parameter.value == (1000, 2000)
예제 #10
0
def test_as_dict():
    level = level_interval("1000/2000")
    parameter = LevelParameter(level)
    assert parameter.asdict() == {"first_level": 1000, "last_level": 2000}
예제 #11
0
def test_slash_none():
    level = level_interval("/")
    parameter = LevelParameter(level)
    assert parameter.value is None
    assert parameter.asdict() == {"first_level": None, "last_level": None}
예제 #12
0
def test_trailing_slash():
    level = level_interval("/2000")
    parameter = LevelParameter(level)
    assert parameter.value == (None, 2000)
예제 #13
0
def test_starting_slash():
    level = level_interval("1000/")
    parameter = LevelParameter(level)
    assert parameter.value == (1000, None)
예제 #14
0
def test_int_tuple():
    level = level_interval(1000, 2000)
    parameter = LevelParameter(level)
    assert parameter.value == (1000, 2000)
예제 #15
0
def test_start_slash_end():
    level = level_interval("1000/2000")
    parameter = LevelParameter(level)
    assert parameter.value == (1000, 2000)
예제 #16
0
def test_class_instance():
    level = level_interval("1000/2000")
    parameter = LevelParameter(level)
    new_parameter = LevelParameter(parameter)
    assert new_parameter.value == (1000, 2000)
예제 #17
0
def test_float_string():
    level = level_interval("1000.50/2000.60")
    parameter = LevelParameter(level)
    assert parameter.value == (1000.5, 2000.6)
예제 #18
0
def test_float_tuple():
    level = level_interval(1000.50, 2000.60)
    parameter = LevelParameter(level)
    assert parameter.value == (1000.5, 2000.6)