def test_cache_works(self): mc = MemoryCache() sentinel = object() mc["foo"] = sentinel assert len(mc) == 1 assert mc["foo"] is sentinel mc.clear() assert len(mc) == 0
def test_returns_copy(self): mc = MemoryCache() data = pd.DataFrame({"x": [0, 1]}) mc["foo"] = data assert mc["foo"] is not mc["foo"] assert_frame_equal(mc["foo"], data)
def test_add_empty_value(self, val: Optional[pd.DataFrame]): mc = MemoryCache() mc["foo"] = val assert "foo" not in mc assert len(mc) == 0
def _cache_converter(value: Optional[Union[str, Path, Cache]]) -> Cache: """Convert ``value`` to :class:`omnipath._core.cache.Cache`.""" if isinstance(value, Cache): return value if value is None: return MemoryCache() return FileCache(value)
def test_dataframe_modification(self): mc = MemoryCache() df = pd.DataFrame({"foo": [1, 2], "bar": [3, 4]}) mc["baz"] = df _ = df.pop("foo") assert "foo" in mc["baz"] assert "bar" in mc["baz"]
def cache_backup(): import omnipath as op cache = deepcopy(op.options.cache) pb = op.options.progress_bar op.options.cache = MemoryCache() op.options.progress_bar = False yield op.options.cache = cache op.options.progress_bar = pb
def server_url(): import omnipath as op cache = deepcopy(op.options.cache) pb = op.options.progress_bar url = op.options.url cd = op.options.convert_dtypes op.options.cache = MemoryCache() op.options.progress_bar = False op.options.url = DEFAULT_OPTIONS.url op.options.convert_dtypes = True yield op.options.cache = cache op.options.progress_bar = pb op.options.url = url op.options.convert_dtypes = cd
def test_deepcopy_work(self): mc = MemoryCache() assert mc is not deepcopy(mc)
def test_copy_does_nothing(self): mc = MemoryCache() assert mc is mc.copy() assert mc is copy(mc)
def test_path_is_None(self): mc = MemoryCache() assert mc.path is None
def test_str_repr(self): mc = MemoryCache() assert str(mc) == f"<{mc.__class__.__name__}[size={len(mc)}]>" assert repr(mc) == f"<{mc.__class__.__name__}[size={len(mc)}]>"