Beispiel #1
0
def test_cstring() -> None:
    c = Complex("dept", "d", "CSTRING", "<=", True, False, "ABC", 0)
    assert c.name == "dept"
    assert c.shortcut == "d"
    assert c.default == "abc"
    assert c.parse("MixedCase") == "mixedcase"
    assert c.parse(None) is None
Beispiel #2
0
def test_other_strings() -> None:
    for stype in ["RESTRING", "TIME", "STRING", "HOST"]:
        c = Complex("compy", "c", stype, "<=", True, False, "ABC", 0)
        assert c.name == "compy"
        assert c.shortcut == "c"
        assert c.default == "ABC"
        assert c.parse("MixedCase") == "MixedCase"
        assert c.parse(None) is None
Beispiel #3
0
def test_double_parsing() -> None:
    c = Complex("disk", "d", "DOUBLE", "<=", True, True, "123.123", 0)
    assert c.name == "disk"
    assert c.shortcut == "d"
    assert c.default == 123.123
    assert c.parse("234.234") == 234.234
    assert c.parse("infinity") == float("inf")

    for expr in ["SDF", None, ""]:
        assert c.parse(expr) == expr
Beispiel #4
0
def test_int_parsing() -> None:
    for itype in ["INT", "RSMAP"]:
        c = Complex("slots", "s", itype, "<=", True, True, "1", 1000)
        assert c.parse("100") == 100
        assert c.default == 1
        assert c.name == "slots"
        assert c.shortcut == "s"

        for expr in ["100.1", "a", None, ""]:
            c.parse(expr) == expr
Beispiel #5
0
def test_excl_parsing() -> None:
    c = Complex("exclusive", "excl", "BOOL", "EXCL", True, True, "0", 1000)
    assert c.default == Memory.value_of("0b")
    assert c.parse("TRuE")
    assert c.parse("true")
    assert c.parse("1")
    assert not c.parse("FALsE")
    assert not c.parse("false")
    assert not c.parse("0")

    for expr in ["yes", "y", "SDF", None, ""]:
        assert c.parse(expr) == expr
Beispiel #6
0
def test_memory_parsing() -> None:
    c = Complex("m_mem_free", "mfree", "MEMORY", "<=", True, True, "0", 0)
    assert c.parse("100") == Memory.value_of("100b")
    assert c.parse("100g") == Memory.value_of("100g")
    assert c.parse("100G") == Memory.value_of("100G")
    assert c.parse("100g") != Memory.value_of("100G")
    assert c.parse("42.123t") == Memory.value_of("42.123t")
    assert c.name == "m_mem_free"
    assert c.shortcut == "mfree"

    for expr in ["blah.", "10gigs", None, ""]:
        assert c.parse(expr) == expr