Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
# PY2 should return the regular (unicode) string
return self.x.encode('utf-8')
else:
return self.x
def __eq__(self, other):
return self.x == other.x
y1 = {
'a': 2,
'b': Y('Gabriel Falcão'),
'c': 'Foo',
}
name = 'Gabriel Falc\xe3o' if PY2 else 'Gabriel Falcão'
expect(safe_repr(y1)).should.equal(compat_repr(
"{'a': 2, 'b': %s, 'c': 'Foo'}" % name
))
def test_nested_dict():
"dicts nested inside values should also get sorted"
X = {'my::all_users': [{'age': 33, 'name': 'John', 'foo': 'bar'}]}
expect(safe_repr(X)).should.equal(compat_repr(
'''{'my::all_users': [{'age': 33, 'foo': 'bar', 'name': 'John'}]}'''
))
def test_basic_list():
"safe_repr should display a simple list"
X = ['one', 'yeah']
expect(safe_repr(X)).should.equal(compat_repr(
"['one', 'yeah']"
))
def test_basic_dict():
"safe_repr should return a sorted repr"
X = {'b': 'd', 'a': 'c'}
expect(safe_repr(X)).should.equal(compat_repr(
"{'a': 'c', 'b': 'd'}"
))
try:
comparison = DeepComparison(self.obj, what, epsilon).compare()
error = False
except AssertionError as e:
error = e
comparison = None
if isinstance(comparison, DeepExplanation):
error = comparison.get_assertion(self.obj, what)
if self.negative:
if error:
return True
msg = '%s should differ from %s, but is the same thing'
raise AssertionError(msg % (safe_repr(self.obj), safe_repr(what)))
else:
if not error:
return True
raise error
def wrapper(self, *args, **kw):
try:
value = func(self, *args, **kw)
except AssertionError as e:
raise AssertionError(e)
msg = "{0}({1}) failed".format(
func.__name__,
", ".join(map(safe_repr, args)),
", ".join(["{0}={1}".format(k, safe_repr(kw[k])) for k in kw]),
)
if PY2:
msg = text_type(msg)
assert value, msg
return value
def __getattr__(self, attr):
try:
return super(VariablesBag, self).__getattribute__(attr)
except AttributeError:
if attr not in dir(VariablesBag):
raise AssertionError(not_here_error % (
attr,
safe_repr(self.__varnames__),
))
def callable(self):
if self.negative:
assert not callable(self.obj), (
'expected `{0}` to not be callable but it is'.format(safe_repr(self.obj)))
else:
assert callable(self.obj), (
'expected {0} to be callable'.format(safe_repr(self.obj)))
return True
def empty(self):
representation = safe_repr(self.obj)
length = len(self.obj)
if self.negative:
assert length > 0, (
"expected `{0}` to not be empty".format(representation))
else:
assert length == 0, (
"expected `{0}` to be empty but it has {1} items".format(representation, length))
return True