Commit 033971be authored by Tomas Krizek's avatar Tomas Krizek

DataMismatch: support DNS RRset as mismatch value

Related knot/resolver-benchmarking#33
parent 8cc77e18
......@@ -8,8 +8,10 @@ from typing import ( # noqa
Any, Callable, Dict, Hashable, ItemsView, Iterator, KeysView, Mapping,
Optional, Set, Sequence, Tuple, Type, Union)
import dns.rrset
# replace Any with 'MismatchValue' once nested types are supported with mypy
MismatchValue = Union[str, Sequence[Any]]
MismatchValue = Union[str, dns.rrset.RRset, Sequence[Any]]
QID = int
WireFormat = bytes
FieldLabel = str
......@@ -30,6 +32,8 @@ class DataMismatch(Exception):
return val
if isinstance(val, collections.abc.Sequence):
return [convert_val_type(item) for item in val]
if isinstance(val, dns.rrset.RRset):
return str(val)
logging.warning(
'DataMismatch: unknown value type (%s), casting to str', type(val),
stack_info=True)
......
......@@ -32,12 +32,12 @@ def compare_rrs(expected: RRset, got: RRset):
""" Compare lists of RR sets, throw exception if different. """
for rr in expected:
if rr not in got:
raise DataMismatch(str(expected), str(got))
raise DataMismatch(expected, got)
for rr in got:
if rr not in expected:
raise DataMismatch(str(expected), str(got))
raise DataMismatch(expected, got)
if len(expected) != len(got):
raise DataMismatch(str(expected), str(got))
raise DataMismatch(expected, got)
return True
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment