Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_freeze():
frozen = freeze([0, 1, 2, {'a': [1, 2, 3]}, {1, 2}])
assert isinstance(frozen, tuple)
assert isinstance(frozen[3], FrozenDict)
assert isinstance(frozen[3]['a'], tuple)
assert isinstance(frozen[4], frozenset)
with pytest.raises(TypeError):
frozen[0] = 10
with pytest.raises(TypeError):
frozen[3]['a'] = 10
:param cond: Either a query that at least one document has to match or
a list of which at least one document has to be contained
in the tested document.
"""
if callable(cond):
def _cmp(value):
return is_sequence(value) and any(cond(e) for e in value)
else:
def _cmp(value):
return is_sequence(value) and any(e in cond for e in value)
return self._generate_test(
lambda value: _cmp(value),
('any', self._path, freeze(cond))
)
def __ne__(self, rhs: Any):
"""
Test a dict value for inequality.
>>> Query().f1 != 42
:param rhs: The value to compare against
"""
return self._generate_test(
lambda value: value != rhs,
('!=', self._path, freeze(rhs))
)
def one_of(self, items: List[Any]) -> QueryImpl:
"""
Check if the value is contained in a list or generator.
>>> Query().f1.one_of(['value 1', 'value 2'])
:param items: The list of items to check with
"""
return self._generate_test(
lambda value: value in items,
('one_of', self._path, freeze(items))
)
{'f1': [1, 2, 3, 4, 5]}
:param cond: Either a query that all documents have to match or a list
which has to be contained in the tested document.
"""
if callable(cond):
def _cmp(value):
return is_sequence(value) and all(cond(e) for e in value)
else:
def _cmp(value):
return is_sequence(value) and all(e in value for e in cond)
return self._generate_test(
lambda value: _cmp(value),
('all', self._path, freeze(cond))
)
def __eq__(self, rhs: Any):
"""
Test a dict value for equality.
>>> Query().f1 == 42
:param rhs: The value to compare against
"""
def test(value):
return value == rhs
return self._generate_test(
lambda value: test(value),
('==', self._path, freeze(rhs))
)