cleanup and a lot more tests
This commit is contained in:
@@ -36,6 +36,12 @@ def test_lines_missing_tokens(line):
|
||||
Dictionary("", dictionary)
|
||||
|
||||
|
||||
def test_invalid_token():
|
||||
dictionary = StringIO("invalid_token")
|
||||
with pytest.raises(ParseError):
|
||||
Dictionary("", dictionary)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"vendor",
|
||||
[
|
||||
@@ -53,6 +59,33 @@ def test_valid_vendor_definitions(vendor):
|
||||
Dictionary("", dictionary)
|
||||
|
||||
|
||||
def test_closing_wrong_vendor():
|
||||
dictionary = StringIO(
|
||||
"VENDOR TEST-VENDOR 1234\n"
|
||||
"BEGIN-VENDOR TEST-VENDOR\n"
|
||||
"END-VENDOR WRONG-VENDOR"
|
||||
)
|
||||
with pytest.raises(ParseError):
|
||||
Dictionary("", dictionary)
|
||||
|
||||
|
||||
def test_nested_vendor():
|
||||
dictionary = StringIO(
|
||||
"VENDOR TEST-VENDOR1 1234\n"
|
||||
"VENDOR TEST-VENDOR2 1235\n"
|
||||
"BEGIN-VENDOR TEST-VENDOR1\n"
|
||||
"BEGIN-VENDOR TEST-VENDOR2"
|
||||
)
|
||||
with pytest.raises(ParseError):
|
||||
Dictionary("", dictionary)
|
||||
|
||||
|
||||
def test_begin_vendor_without_definition():
|
||||
dictionary = StringIO("BEGIN-VENDOR TEST-VENDOR")
|
||||
with pytest.raises(ParseError):
|
||||
Dictionary("", dictionary)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"vendor",
|
||||
[
|
||||
@@ -86,7 +119,8 @@ def test_valid_attribute_numbers(number):
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"invalid_number", ["ABCD", "-1", "inf", "INF", "-INF", "2e4", "2.5e3"],
|
||||
"invalid_number",
|
||||
["1000", "ABCD", "-1", "inf", "INF", "-INF", "2e4", "2.5e3"],
|
||||
)
|
||||
def test_invalid_attribute_numbers(invalid_number):
|
||||
dictionary = StringIO(f"ATTRIBUTE NAME {invalid_number} integer64")
|
||||
@@ -115,6 +149,12 @@ def test_attribute_number_limits(type_length):
|
||||
Dictionary("", dictionary)
|
||||
|
||||
|
||||
def test_invalid_attr_type():
|
||||
dictionary = StringIO("ATTRIBUTE NAME 2 invalid")
|
||||
with pytest.raises(ParseError):
|
||||
Dictionary("", dictionary)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("value", ["1", "0x1", "0o1"])
|
||||
def test_value_definition(value):
|
||||
dictionary = StringIO(
|
||||
@@ -249,7 +289,7 @@ def test_valid_datatypes_in_vendor_space(datatype):
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"datatype", ["concat", "extended", "long-extended", "evs",]
|
||||
"datatype", ["concat", "extended", "long-extended", "evs"]
|
||||
)
|
||||
def test_invalid_datatypes_in_vendor_space(datatype):
|
||||
dictionary = StringIO(
|
||||
@@ -266,10 +306,74 @@ def test_invalid_datatypes_in_vendor_space(datatype):
|
||||
"invalid_number",
|
||||
["ABCD", "-1", "inf", "INF", "-INF", "0.1", "2e4", "2.5e3"],
|
||||
)
|
||||
def test_invalid_attribute_numbers(invalid_number):
|
||||
def test_invalid_value_numbers(invalid_number):
|
||||
dictionary = StringIO(
|
||||
f"ATTRIBUTE TEST-ATTRIBUTE 1 integer\n"
|
||||
f"VALUE TEST-ATTRIBUTE TEST-VALUE {invalid_number}"
|
||||
)
|
||||
with pytest.raises(ParseError):
|
||||
Dictionary("", dictionary)
|
||||
|
||||
|
||||
def test_value_for_non_existing_attribute():
|
||||
dictionary = StringIO("VALUE ATTRNAME VALUENAME 1234")
|
||||
with pytest.raises(ParseError):
|
||||
Dictionary("", dictionary)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"datatype",
|
||||
[
|
||||
"string",
|
||||
"octets",
|
||||
"abinary",
|
||||
"ipaddr",
|
||||
"ipv4prefix",
|
||||
"ipv6addr",
|
||||
"ipv6prefix",
|
||||
"combo-ip",
|
||||
"ifid",
|
||||
"ether",
|
||||
"tlv",
|
||||
],
|
||||
)
|
||||
def test_value_for_wrong_datatype(datatype):
|
||||
dictionary = StringIO(
|
||||
f"ATTRIBUTE NAME 123 {datatype}\n" "VALUE NAME VNAME 256"
|
||||
)
|
||||
with pytest.raises(ParseError):
|
||||
Dictionary("", dictionary)
|
||||
|
||||
|
||||
def test_unimplemented_tlvs():
|
||||
dictionary = StringIO("BEGIN-TLV")
|
||||
with pytest.raises(NotImplementedError):
|
||||
Dictionary("", dictionary)
|
||||
dictionary = StringIO("END-TLV")
|
||||
with pytest.raises(NotImplementedError):
|
||||
Dictionary("", dictionary)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("flag", [1, 2, 3])
|
||||
def test_valid_attribute_encrpytion_flags(flag):
|
||||
dictionary = StringIO(f"ATTRIBUTE NAME 123 octets encrypt={flag}")
|
||||
Dictionary("", dictionary)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("flag", ["0.1", "0", "4", "0x1", "0o2", "user", ""])
|
||||
def test_invalid_attribute_encrpytion_flags(flag):
|
||||
dictionary = StringIO(f"ATTRIBUTE NAME 123 octets encrypt={flag}")
|
||||
with pytest.raises(ParseError):
|
||||
Dictionary("", dictionary)
|
||||
|
||||
|
||||
def test_has_tag_flag():
|
||||
dictionary = StringIO("ATTRIBUTE NAME 123 octets has_tag")
|
||||
Dictionary("", dictionary)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("invalid_flag", ["blablub", "encrypt=2=2", "concat"])
|
||||
def test_invalid_attribute_flags(invalid_flag):
|
||||
dictionary = StringIO(f"ATTRIBUTE NAME 123 octets {invalid_flag}")
|
||||
with pytest.raises(ParseError):
|
||||
Dictionary("", dictionary)
|
||||
|
||||
Reference in New Issue
Block a user