def test_memoized(args, kwargs): @memoized def f(*args, **kwargs): return 'return-value' assert f(*args, **kwargs) == 'return-value' key = stable_args(*args, **kwargs) assert list(f.cache.keys()) == [key] assert f.cache[key] == 'return-value'
def test_memoized_unhashable(args, kwargs): """Check that an exception is raised clearly""" @memoized def f(*args, **kwargs): return None with pytest.raises(llnl.util.lang.UnhashableArguments) as exc_info: f(*args, **kwargs) exc_msg = str(exc_info.value) key = stable_args(*args, **kwargs) assert str(key) in exc_msg assert "function 'f'" in exc_msg
def test_equal_args(args1, kwargs1, args2, kwargs2): assert stable_args(*args1, **kwargs1) == stable_args(*args2, **kwargs2)