def test_print_cache(capfd): clear_cache() _identity(x) info = _identity.cache_info() print_cache() resout, _ = capfd.readouterr() assert resout.find('_identity ' + str(info)) >= 0
def test_sympyissue_8825(): t1, t2 = symbols('t1:3') d = weakref.WeakKeyDictionary([(t1, 1), (t2, 2)]) assert sstr(list(ordered(d.items()))) == '[(t1, 1), (t2, 2)]' del t1 clear_cache() gc.collect() assert sstr(list(ordered(d.items()))) == '[(t2, 2)]'
def test_sympyissue_8825(): import weakref a, b = symbols('a b') d = weakref.WeakKeyDictionary([(a, 1), (b, 2)]) assert sstr(list(ordered(d.items()))) == '[(a, 1), (b, 2)]' del a clear_cache() assert sstr(list(ordered(d.items()))) == '[(b, 2)]'
def test_pow_eval_subs_no_cache(): s = 1 / sqrt(x**2) # This bug only appeared when the cache was turned off. clear_cache() # This used to fail with a wrong result. # It incorrectly returned 1/sqrt(x**2) before. result = s.subs({sqrt(x**2): y}) assert result == 1 / y
def test_sympyissue_7688(): f = Function('f') # actually an UndefinedFunction clear_cache() class A(UndefinedFunction): pass a = A('f') assert isinstance(a, type(f))
def test_sympyissue_7687(): f = Function('f')(x) ff = Function('f')(x) match_with_cache = f.match(ff) assert isinstance(f, type(ff)) clear_cache() ff = Function('f')(x) assert isinstance(f, type(ff)) assert match_with_cache == f.match(ff)
def test_pow_eval_subs_no_cache(): s = 1/sqrt(x**2) # This bug only appeared when the cache was turned off. clear_cache() # This used to fail with a wrong result. # It incorrectly returned 1/sqrt(x**2) before. result = s.subs({sqrt(x**2): y}) assert result == 1/y
def test_sympyissue_7688(): from diofant.core.function import Function, UndefinedFunction f = Function('f') # actually an UndefinedFunction clear_cache() class A(UndefinedFunction): pass a = A('f') assert isinstance(a, type(f))
def test_sympyissue_7687(): from diofant.core.function import Function from diofant.abc import x f = Function('f')(x) ff = Function('f')(x) match_with_cache = ff.matches(f) assert isinstance(f, type(ff)) clear_cache() ff = Function('f')(x) assert isinstance(f, type(ff)) assert match_with_cache == ff.matches(f)
def test_print_cache(capfd): clear_cache() wrapped = _identity.__wrapped__ _identity(x) item = str(wrapped) head = '='*len(item) res = (head + "\n" + item + "\n" + head + "\n" + " ((Symbol('x'), <class 'diofant.core.symbol.Symbol'>), (True,)) : x\n") print_cache() resout, _ = capfd.readouterr() assert resout == res assert dict(CACHE)[wrapped] == {((x, Symbol), (True,)): x}
def file_clear_cache(): clear_cache()