Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def assertions():
assert that(something).deep_equals({
'my::all_users': [
{'name': 'John', 'age': 33, 'bar': 'foo'},
],
})
assert that(assertions).raises(
AssertionError, compat_repr(
"given\n"
"X = {{'my::all_users': [{{'age': 33, 'foo': 'bar', 'name': 'John'}}]}}\n"
" and\n"
"Y = {{'my::all_users': [{{'age': 33, 'bar': 'foo', 'name': 'John'}}]}}\n"
"X['my::all_users'][0] has the key \"{0}\" whereas Y['my::all_users'][0] does not"
).format(safe_repr('foo')))
'one': 'yeah',
}
def assertions():
assert that(something).deep_equals({
'two': 'yeah',
})
assert that(assertions).raises(
AssertionError, compat_repr(
"given\n"
"X = {{'one': 'yeah'}}\n"
" and\n"
"Y = {{'two': 'yeah'}}\n"
"X has the key \"{0}\" whereas Y does not"
).format(safe_repr('one'))
)
def get_header(self, X, Y, suffix):
params = (safe_repr(X), safe_repr(Y), text_type(suffix))
header = "given\nX = {0}\n and\nY = {1}\n{2}".format(*params)
return yellow(header).strip()
def compare_dicts(self, X, Y):
c = self.get_context()
x_keys = list(X.keys())
y_keys = list(Y.keys())
diff_x = list(set(x_keys).difference(set(y_keys)))
diff_y = list(set(y_keys).difference(set(x_keys)))
if diff_x:
msg = "X{0} has the key {1!r} whereas Y{2} does not".format(
red(c.current_X_keys),
safe_repr(diff_x[0]),
green(c.current_Y_keys))
return DeepExplanation(msg)
elif diff_y:
msg = "X{0} does not have the key {1!r} whereas Y{2} has it".format(
red(c.current_X_keys),
safe_repr(diff_y[0]),
green(c.current_Y_keys))
return DeepExplanation(msg)
elif X == Y:
return True
else:
for key_X in x_keys:
self.key_X = key_X
def get_keys(i):
if not i:
return ''
return '[{0}]'.format(']['.join(map(safe_repr, i)))