From aa4e0cd60c791e6a377fdfe05b32d20dae829632 Mon Sep 17 00:00:00 2001 From: ljnsn <82611987+ljnsn@users.noreply.github.com> Date: Tue, 20 Dec 2022 01:27:12 +0100 Subject: [PATCH] Raise error on invalid path. Fixes #5 --- pandas_ods_reader/main.py | 3 +++ tests/test_read_ods.py | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/pandas_ods_reader/main.py b/pandas_ods_reader/main.py index a043ab8..8d0e650 100644 --- a/pandas_ods_reader/main.py +++ b/pandas_ods_reader/main.py @@ -34,6 +34,9 @@ def read_ods( Returns: The content of the specified sheet as a DataFrame. """ + path = file_or_path if isinstance(file_or_path, Path) else Path(file_or_path) + if not path.is_file(): + raise FileNotFoundError(f"file {file_or_path} does not exist") backend = EXT_MAP.get(Path(file_or_path).suffix, ods) return algo.read_data( backend, diff --git a/tests/test_read_ods.py b/tests/test_read_ods.py index aa3aa9c..730bd29 100644 --- a/tests/test_read_ods.py +++ b/tests/test_read_ods.py @@ -156,3 +156,9 @@ class TestOdsReader: assert len(df) == 8 assert len(df.columns) == 5 assert df.columns.tolist() == ["a", "b", "c", "d", "e"] + + def test_invalid_path(self): + + path = rsc / "does-not-exist.ods" + with pytest.raises(FileNotFoundError, match="does not exist"): + read_ods(path)