-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
35 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
from pathlib import Path | ||
|
||
import pandas as pd | ||
|
||
from examples.helpers import with_parquet_cache | ||
|
||
|
||
class TestWithParquetCache: | ||
def test_creates_and_fetches_cache(self, tmp_path: Path): | ||
fp = tmp_path / "test.parquet" | ||
sample_df = pd.DataFrame({"a": [1, 2, 3]}) | ||
|
||
@with_parquet_cache(fp=tmp_path / "test.parquet") | ||
def myfunc() -> pd.DataFrame: | ||
return sample_df | ||
|
||
assert not fp.exists() | ||
_df = myfunc() | ||
pd.testing.assert_frame_equal(_df, sample_df) | ||
assert fp.exists() | ||
|
||
df2 = myfunc() | ||
pd.testing.assert_frame_equal(df2, sample_df) | ||
|
||
def test_doesnt_run_the_func_if_file_exists(self, tmp_path: Path): | ||
fp = tmp_path / "test.parquet" | ||
sample_df = pd.DataFrame({"a": [1, 2, 3]}) | ||
sample_df.to_parquet(fp) | ||
|
||
@with_parquet_cache(fp=tmp_path / "test.parquet") | ||
def myfunc() -> pd.DataFrame: | ||
return 1 / 0 | ||
|
||
_df = myfunc() | ||
pd.testing.assert_frame_equal(_df, sample_df) |