Skip to content

Commit

Permalink
Create test_helpers.py
Browse files Browse the repository at this point in the history
  • Loading branch information
aclerc committed Apr 22, 2024
1 parent faf5bb9 commit 7a03205
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions tests/test_helpers.py
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)

0 comments on commit 7a03205

Please sign in to comment.