Ejemplo n.º 1
0
def test_valid_map():
    tmap = TMap(key_type=TI32(), value_type=TString())
    assert tmap.validate_arg({}) is None
    assert tmap.validate_arg({3: "dog", 4: "cat"}) is None
    nested_tmap = TMap(key_type=TI32(),
                       value_type=TMap(key_type=TString(), value_type=TI32()))
    assert nested_tmap.validate_arg({3: {"test": 4}, 1: {"map": 3231}}) is None
Ejemplo n.º 2
0
def test_invalid_map():
    tmap = TMap(key_type=TI32(), value_type=TString())
    assert tmap.validate_arg(4) == ["Expected dict but got int"]
    assert tmap.validate_arg({
        3: 4,
        5: 2
    }) == [
        "Value for key '3' in map invalid: 'Expected str but got int'",
        "Value for key '5' in map invalid: 'Expected str but got int'",
    ]
    assert tmap.validate_arg({
        "3": 4,
        5: "2"
    }) == [
        "Key '3' in map invalid: 'Expected int but got str'",
        "Value for key '3' in map invalid: 'Expected str but got int'",
    ]