How to use the forbiddenfruit.reverse function in forbiddenfruit

To help you get started, we’ve selected a few forbiddenfruit examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github clarete / forbiddenfruit / tests / unit / test_forbidden_fruit.py View on Github external
def test_dunder_reverse():
    def type_error_str(self):
        return 'type error'
    curse(TypeError, '__str__', type_error_str)
    te = TypeError("testing")
    assert str(te) == "type error"

    reverse(TypeError, '__str__')
    assert str(te) == "testing"
github clarete / forbiddenfruit / tests / unit / test_forbidden_fruit.py View on Github external
def test_cursing_a_reversed_curse():
    curse(str, 'one', 1)
    assert str.one == 1

    reverse(str, 'one')
    curse(str, 'one', 2)
    assert str.one == 2
github clarete / forbiddenfruit / tests / unit / test_forbidden_fruit.py View on Github external
def test_reversing_a_builtin():
    # Given that I have a cursed object
    curse(str, 'stuff', property(lambda s: s * 2))

    # When I bless it
    reverse(str, 'stuff')

    # Then I see that str won't contain
    assert 'stuff' not in dir(str)
github clarete / forbiddenfruit / tests / unit / test_forbidden_fruit.py View on Github external
def test_dunder_list_revert():
    """Test reversion of a curse with dunders"""
    def map_list(func, list_):
        if not callable(func):
            raise NotImplementedError()
        return map(func, list_)

    curse(list, "__add__", map_list)

    list_ = list(range(10))
    times_2 = lambda x: x * 2

    assert list(times_2 + list_) == list(range(0, 20, 2))

    reverse(list, "__add__")
    try:
        times_2 + list_
    except TypeError:
        pass
    else:
        # should always raise an exception
        assert False
github PythonCharmers / python-future / future / hacks / cursedbytes.py View on Github external
def new_bytes_context():
    curse(bytes, "__oldrepr__", bytes.__repr__)
    curse(bytes, "_c___repr", myrepr)
    curse(bytes, "fromhex", classmethod(fromhex))
    yield
    reverse(bytes, "fromhex")
    reverse(bytes, "_c___repr")
    reverse(bytes, "__oldrepr__")
github PythonCharmers / python-future / future / hacks / cursedbytes.py View on Github external
def new_bytes_context():
    curse(bytes, "__oldrepr__", bytes.__repr__)
    curse(bytes, "_c___repr", myrepr)
    curse(bytes, "fromhex", classmethod(fromhex))
    yield
    reverse(bytes, "fromhex")
    reverse(bytes, "_c___repr")
    reverse(bytes, "__oldrepr__")
github PythonCharmers / python-future / future / hacks / cursedbytes.py View on Github external
def new_bytes_context():
    curse(bytes, "__oldrepr__", bytes.__repr__)
    curse(bytes, "_c___repr", myrepr)
    curse(bytes, "fromhex", classmethod(fromhex))
    yield
    reverse(bytes, "fromhex")
    reverse(bytes, "_c___repr")
    reverse(bytes, "__oldrepr__")