tests: Use fnmatch for strings in partial_match.
This commit is contained in:
parent
3fac74656e
commit
6e7d6fb00e
@ -29,6 +29,7 @@ from helpers import utils # pylint: disable=import-error
|
||||
({'a': [1, 2, 3]}, {'a': [1]}),
|
||||
({'a': [1, 2, 3]}, {'a': [..., 2]}),
|
||||
(1.0, 1.00000001),
|
||||
("foobarbaz", "foo*baz"),
|
||||
])
|
||||
def test_partial_compare_equal(val1, val2):
|
||||
assert utils.partial_compare(val1, val2)
|
||||
@ -43,6 +44,7 @@ def test_partial_compare_equal(val1, val2):
|
||||
([1], {1: 2}),
|
||||
({1: 1}, {1: [1]}),
|
||||
({'a': [1, 2, 3]}, {'a': [..., 3]}),
|
||||
("foo*baz", "foobarbaz"),
|
||||
])
|
||||
def test_partial_compare_not_equal(val1, val2):
|
||||
assert not utils.partial_compare(val1, val2)
|
||||
|
@ -20,6 +20,9 @@
|
||||
"""Partial comparison of dicts/lists."""
|
||||
|
||||
|
||||
import fnmatch
|
||||
|
||||
|
||||
def _partial_compare_dict(val1, val2):
|
||||
for key in val2:
|
||||
if key not in val1:
|
||||
@ -71,6 +74,9 @@ def partial_compare(val1, val2):
|
||||
elif isinstance(val2, float):
|
||||
print("Doing float comparison")
|
||||
equal = abs(val1 - val2) < 0.00001
|
||||
elif isinstance(val2, str):
|
||||
print("Doing string comparison")
|
||||
equal = fnmatch.fnmatchcase(val1, val2)
|
||||
else:
|
||||
print("Comparing via ==")
|
||||
equal = val1 == val2
|
||||
|
Loading…
Reference in New Issue
Block a user