Beispiel #1
0
def test_clear_backends(nullary_mm):
    obj = object()
    obj2 = object()
    be = Backend()
    be.__ua_function__ = lambda f, a, kw: obj

    be2 = Backend()
    be2.__ua_function__ = lambda f, a, kw: obj2

    ua.set_global_backend(be)
    ua.register_backend(be2)

    ua.clear_backends(Backend.__ua_domain__, registered=True, globals=True)
    with pytest.raises(ua.BackendNotImplementedError):
        nullary_mm()
Beispiel #2
0
def test_clear_backends(cleanup_backends):
    obj = object()
    obj2 = object()
    be = Backend()
    be.__ua_function__ = lambda f, a, kw: obj

    be2 = Backend()
    be2.__ua_function__ = lambda f, a, kw: obj2
    mm = ua.generate_multimethod(lambda: (), lambda a, kw, d: (a, kw),
                                 "ua_tests")

    ua.set_global_backend(be)
    ua.register_backend(be2)

    ua.clear_backends(Backend.__ua_domain__, registered=True, globals=True)
    with pytest.raises(ua.BackendNotImplementedError):
        mm()
Beispiel #3
0
def test_multidomain_backends():
    n_domains = 2
    be = DisableBackend(domain=["ua_tests" + str(i) for i in range(n_domains)])

    mms = [
        ua.generate_multimethod(lambda: (), lambda a, kw, d: (a, kw),
                                "ua_tests" + str(i)) for i in range(n_domains)
    ]

    def assert_no_backends():
        for i in range(len(mms)):
            with pytest.raises(ua.BackendNotImplementedError):
                mms[i]()

    def assert_backend_active(backend):
        assert all(mms[i]() is backend.ret for i in range(len(mms)))

    assert_no_backends()

    with ua.set_backend(be):
        assert_backend_active(be)

    ua.set_global_backend(be)
    assert_backend_active(be)

    with ua.skip_backend(be):
        assert_no_backends()

    assert_backend_active(be)

    for i in range(len(mms)):
        ua.clear_backends(mms[i].domain, globals=True)

        with pytest.raises(ua.BackendNotImplementedError):
            mms[i]()

        for j in range(i + 1, len(mms)):
            assert mms[j]() is be.ret

    assert_no_backends()

    ua.register_backend(be)
    assert_backend_active(be)
Beispiel #4
0
 def cleanup():
     ua.clear_backends("ua_tests", registered=True, globals=True)