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_cursed_context_manager():
"The `cursed` context manager should curse an existing symbols in a scope"
# Given that I have an instance of a python class
obj = {'a': 1, 'b': 2}
# When I curse an instance method
with cursed(dict, "open_box", lambda self: 'surprise'):
# Then I see that my object was cursed properly
assert obj.open_box() == 'surprise'
# And it was reversed
assert "open_box" not in dir(obj)
assert "open_box" not in dir(dict)
@cursed(dict, "open_box", lambda self: 'surprise')
def function():
# Then I see that my object was cursed properly
assert obj.open_box() == 'surprise'