From 4e02c4427604dc0e676718066b11c0d14d6de56e Mon Sep 17 00:00:00 2001 From: iuvbio Date: Fri, 20 Aug 2021 19:14:26 +0200 Subject: [PATCH] add fods tests --- tests/test_read_ods.py | 80 ++++++++++++++++++++++++------------------ 1 file changed, 45 insertions(+), 35 deletions(-) diff --git a/tests/test_read_ods.py b/tests/test_read_ods.py index 4537702..772d650 100644 --- a/tests/test_read_ods.py +++ b/tests/test_read_ods.py @@ -19,117 +19,127 @@ mixed_dtypes_file = "mixed_dtypes.ods" class TestOdsReader: - - def test_header_file_simple(self): + @pytest.mark.parametrize("suffix", [".ods", ".fods"]) + def test_header_file_simple(self, suffix): path = rsc / header_file - df = read_ods(path) + df = read_ods(path.with_suffix(suffix)) assert isinstance(df, pd.DataFrame) assert len(df) == 10 - assert (len(df.columns) == 5) + assert len(df.columns) == 5 - def test_header_file_with_int(self): + @pytest.mark.parametrize("suffix", [".ods", ".fods"]) + def test_header_file_with_int(self, suffix): path = rsc / header_file - df = read_ods(path, 1) + df = read_ods(path.with_suffix(suffix), 1) assert isinstance(df, pd.DataFrame) assert len(df) == 10 - assert (len(df.columns) == 5) + assert len(df.columns) == 5 - def test_header_file_with_str(self): + @pytest.mark.parametrize("suffix", [".ods", ".fods"]) + def test_header_file_with_str(self, suffix): path = rsc / header_file - df = read_ods(path, "Sheet1") + df = read_ods(path.with_suffix(suffix), "Sheet1") assert isinstance(df, pd.DataFrame) assert len(df) == 10 - assert (len(df.columns) == 5) + assert len(df.columns) == 5 - def test_header_file_with_cols(self): + @pytest.mark.parametrize("suffix", [".ods", ".fods"]) + def test_header_file_with_cols(self, suffix): path = rsc / header_file columns = ["One", "Two", "Three", "Four", "Five"] - df = read_ods(path, "Sheet1", columns=columns) + df = read_ods(path.with_suffix(suffix), "Sheet1", columns=columns) assert list(df.columns) == columns assert len(df) == 10 - assert (len(df.columns) == 5) + assert len(df.columns) == 5 - def test_no_header_file_no_cols(self): + @pytest.mark.parametrize("suffix", [".ods", ".fods"]) + def test_no_header_file_no_cols(self, suffix): path = rsc / no_header_file - df = read_ods(path, 1, headers=False) + df = read_ods(path.with_suffix(suffix), 1, headers=False) - assert list(df.columns) == [ - f"column.{i}" for i in range(len(df.columns))] + assert list(df.columns) == [f"column.{i}" for i in range(len(df.columns))] assert len(df) == 10 - assert (len(df.columns) == 5) + assert len(df.columns) == 5 - def test_no_header_file_with_cols(self): + @pytest.mark.parametrize("suffix", [".ods", ".fods"]) + def test_no_header_file_with_cols(self, suffix): path = rsc / no_header_file columns = ["A", "B", "C", "D", "E"] - df = read_ods(path, 1, headers=False, columns=columns) + df = read_ods(path.with_suffix(suffix), 1, headers=False, columns=columns) assert list(df.columns) == columns assert len(df) == 10 - def test_duplicated_column_names(self): + @pytest.mark.parametrize("suffix", [".ods", ".fods"]) + def test_duplicated_column_names(self, suffix): path = rsc / duplicated_column_names_file - df = read_ods(path, 1) + df = read_ods(path.with_suffix(suffix), 1) assert isinstance(df, pd.DataFrame) assert len(df.columns) == 4 assert "website.1" in df.columns - def test_header_file_col_len(self): + @pytest.mark.parametrize("suffix", [".ods", ".fods"]) + def test_header_file_col_len(self, suffix): path = rsc / col_len_file - df = read_ods(path, 1) + df = read_ods(path.with_suffix(suffix), 1) assert isinstance(df, pd.DataFrame) assert len(df) == 10 - assert (len(df.columns) == 5) + assert len(df.columns) == 5 - def test_wrong_id_type(self): + @pytest.mark.parametrize("suffix", [".ods", ".fods"]) + def test_wrong_id_type(self, suffix): path = rsc / header_file with pytest.raises(ValueError) as e_info: - read_ods(path, 1.0) + read_ods(path.with_suffix(suffix), 1.0) assert e_info.match("Sheet id has to be either `str` or `int`") - def test_non_existent_sheet(self): + @pytest.mark.parametrize("suffix", [".ods", ".fods"]) + def test_non_existent_sheet(self, suffix): path = rsc / header_file sheet_name = "No_Sheet" with pytest.raises(KeyError) as e_info: - read_ods(path, sheet_name) + read_ods(path.with_suffix(suffix), sheet_name) assert e_info.match(f"There is no sheet named {sheet_name}") - def test_missing_header(self): + @pytest.mark.parametrize("suffix", [".ods", ".fods"]) + def test_missing_header(self, suffix): path = rsc / missing_header_file - df = read_ods(path, 1) + df = read_ods(path.with_suffix(suffix), 1) assert isinstance(df, pd.DataFrame) assert len(df) == 10 - assert (len(df.columns) == 5) + assert len(df.columns) == 5 assert df.columns[2] == "unnamed.1" - def test_mixed_dtypes(self): + @pytest.mark.parametrize("suffix", [".ods", ".fods"]) + def test_mixed_dtypes(self, suffix): path = rsc / mixed_dtypes_file - df = read_ods(path, 1) + df = read_ods(path.with_suffix(suffix), 1) assert isinstance(df, pd.DataFrame) assert len(df) == 10 - assert (len(df.columns) == 5) + assert len(df.columns) == 5 type_list = [float, object, float, float, object] assert df.dtypes.tolist() == type_list