Helper function to compare nested structures in tests.
This commit is contained in:
@@ -0,0 +1,38 @@
|
|||||||
|
from functools import singledispatch
|
||||||
|
|
||||||
|
|
||||||
|
def assert_same_type(f):
|
||||||
|
def wrapper(a, b):
|
||||||
|
if type(a) != type(b):
|
||||||
|
raise TypeError("Non-matching types")
|
||||||
|
return f(a, b)
|
||||||
|
return wrapper
|
||||||
|
|
||||||
|
|
||||||
|
@singledispatch
|
||||||
|
@assert_same_type
|
||||||
|
def is_subset(model, obj):
|
||||||
|
return model == obj
|
||||||
|
|
||||||
|
|
||||||
|
@is_subset.register(dict)
|
||||||
|
@assert_same_type
|
||||||
|
def _(model, obj):
|
||||||
|
for key, value in model.items():
|
||||||
|
if key not in obj or not is_subset(value, obj[key]):
|
||||||
|
return False
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
@is_subset.register(list)
|
||||||
|
@assert_same_type
|
||||||
|
def _(model, obj):
|
||||||
|
if type(model) != type(obj):
|
||||||
|
raise TypeError("Non-matching types")
|
||||||
|
return is_subset(set(model), set(obj))
|
||||||
|
|
||||||
|
|
||||||
|
@is_subset.register(set)
|
||||||
|
@assert_same_type
|
||||||
|
def _(model, obj):
|
||||||
|
return model <= obj
|
||||||
@@ -7,6 +7,7 @@ import subprocess
|
|||||||
|
|
||||||
import requests
|
import requests
|
||||||
from environconfig import EnvironConfig, StringVar, IntVar, BooleanVar
|
from environconfig import EnvironConfig, StringVar, IntVar, BooleanVar
|
||||||
|
from comparedict import is_subset
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user