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_nested_equal():
def callback_a():
return 'foo'
def callback_b():
return 'foo'
a = Fault('id foo', callback_a).lower().b64encode()
b = Fault('id foo', callback_b).lower().b64encode()
assert id(a) != id(b)
assert a == b
def test_format_into():
def callback():
return 'foo'
a = Fault('id foo', callback).format_into('This is my secret: "{}"')
assert a.value == 'This is my secret: "foo"'
def test_not_equal_b64encode():
def callback_a():
return 'foo'
def callback_b():
return 'foo'
a = Fault('id foo', callback_a).b64encode()
b = Fault('id bar', callback_b).b64encode()
assert id(a) != id(b)
assert a != b
def test_nested_not_equal_because_of_operators():
def callback_a():
return 'foo'
def callback_b():
return 'foo'
a = Fault('id foo', callback_a).lower().b64encode()
b = Fault('id foo', callback_b).lower()
assert id(a) != id(b)
assert a != b
def test_equal_lower():
def callback_a():
return 'foo'
def callback_b():
return 'foo'
a = Fault('id foo', callback_a).lower()
b = Fault('id foo', callback_b).lower()
assert id(a) != id(b)
assert a == b
def test_order():
def callback_a():
return 'foo'
def callback_b():
return 'bar'
def callback_c():
return '0first'
a = Fault('id foo', callback_a)
b = Fault('id bar', callback_b)
c = Fault('id 0first', callback_c)
lst = sorted([a, b, c])
assert lst[0].value == '0first'
assert lst[1].value == 'bar'
assert lst[2].value == 'foo'
def test_add_plain_nonstring():
def callback():
return 4
a = Fault('id foo', callback)
b = a + 8
assert b.value == 12
def decrypt_file_as_base64(self, source_path, key=None):
return Fault(
'bw secrets decrypt_file_as_base64',
self._decrypt_file_as_base64,
source_path=source_path,
key=key,
)
def default(self, obj):
if isinstance(obj, Fault):
return obj.value
if isinstance(obj, set):
return sorted(obj)
if isinstance(obj, bytes):
return force_text(obj)
else:
raise ValueError(_("illegal metadata value type: {}").format(repr(obj)))
def default(self, obj):
if isinstance(obj, Fault):
return self.default(obj.value)
elif isinstance(obj, set):
return sorted(obj)
else:
return JSONEncoder.default(self, obj)