Skip to content

Commit

Permalink
Added test_callable_save
Browse files Browse the repository at this point in the history
Signed-off-by: Elena Khaustova <[email protected]>
  • Loading branch information
ElenaKhaustova committed Jan 7, 2025
1 parent f35b850 commit 262c059
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions kedro-datasets/tests/partitions/test_partitioned_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ def filepath_csvs(tmp_path):
]


def original_data_callable():
return pd.DataFrame({"foo": 42, "bar": ["a", "b", None]})


class FakeDataset: # pylint: disable=too-few-public-methods
pass

Expand Down Expand Up @@ -101,6 +105,22 @@ def test_save(self, dataset, local_csvs, suffix):
reloaded_data = loaded_partitions[part_id]()
assert_frame_equal(reloaded_data, original_data)

@pytest.mark.parametrize("dataset", ["kedro_datasets.pickle.PickleDataset"])
@pytest.mark.parametrize("suffix", ["", ".csv"])
def test_callable_save(self, dataset, local_csvs, suffix):
pds = PartitionedDataset(
path=str(local_csvs), dataset=dataset, filename_suffix=suffix
)

part_id = "new/data"
pds.save({part_id: original_data_callable})

assert (local_csvs / "new" / ("data" + suffix)).is_file()
loaded_partitions = pds.load()
assert part_id in loaded_partitions
reloaded_data = loaded_partitions[part_id]()
assert reloaded_data == original_data_callable

@pytest.mark.parametrize("dataset", LOCAL_DATASET_DEFINITION)
@pytest.mark.parametrize("suffix", ["", ".csv"])
def test_lazy_save(self, dataset, local_csvs, suffix):
Expand Down

0 comments on commit 262c059

Please sign in to comment.