Example #1
0
def test_nested_caches():
    with Cache() as c1:
        with Cache() as c2:
            assert Cache.get() is c2
            assert len(Cache.local.stack) == 2
        assert Cache.get() is c1
        assert len(Cache.local.stack) == 1
    assert len(Cache.local.stack) == 0
Example #2
0
def test_css_called_twice():
    f = e.css('h1')
    response = create_response(example)
    with Cache():
        assert f(response) == f(response)
Example #3
0
def test_cache():
    with Cache() as c1:
        assert cache_me(3) == '3'
        assert cache_me(3) == '3'
        assert Cache.get() is c1
        assert len(Cache.get()) == 1
Example #4
0
def test_cache_attribute_error():
    with pytest.raises(AttributeError):
        with Cache():
            # create AttributeError in __exit__
            del Cache.local.stack
Example #5
0
def test_cache_unhashable():
    with Cache():
        assert cache_me([3]) == '[3]'
        assert len(Cache.get()) == 0