Remove outer test class and add typing to tests.
This commit is contained in:
parent
0b5a1e0511
commit
11111043cd
|
|
@ -19,10 +19,9 @@ mixed_dtypes_file = "mixed_dtypes.ods"
|
|||
skiprows_file = "example_skiprows.ods"
|
||||
|
||||
|
||||
class TestOdsReader:
|
||||
@pytest.mark.parametrize("suffix", [".ods", ".fods"])
|
||||
def test_header_file_simple(self, suffix):
|
||||
|
||||
def test_header_file_simple(suffix: str) -> None:
|
||||
"""Test a simple file with headers."""
|
||||
path = rsc / header_file
|
||||
df = read_ods(path.with_suffix(suffix))
|
||||
|
||||
|
|
@ -30,9 +29,10 @@ class TestOdsReader:
|
|||
assert len(df) == 10
|
||||
assert len(df.columns) == 5
|
||||
|
||||
@pytest.mark.parametrize("suffix", [".ods", ".fods"])
|
||||
def test_header_file_with_int(self, suffix):
|
||||
|
||||
@pytest.mark.parametrize("suffix", [".ods", ".fods"])
|
||||
def test_header_file_with_int(suffix: str) -> None:
|
||||
"""Test referencing a sheet by index."""
|
||||
path = rsc / header_file
|
||||
df = read_ods(path.with_suffix(suffix), 1)
|
||||
|
||||
|
|
@ -40,9 +40,10 @@ class TestOdsReader:
|
|||
assert len(df) == 10
|
||||
assert len(df.columns) == 5
|
||||
|
||||
@pytest.mark.parametrize("suffix", [".ods", ".fods"])
|
||||
def test_header_file_with_str(self, suffix):
|
||||
|
||||
@pytest.mark.parametrize("suffix", [".ods", ".fods"])
|
||||
def test_header_file_with_str(suffix: str) -> None:
|
||||
"""Test referencing a sheet by name."""
|
||||
path = rsc / header_file
|
||||
df = read_ods(path.with_suffix(suffix), "Sheet1")
|
||||
|
||||
|
|
@ -50,9 +51,10 @@ class TestOdsReader:
|
|||
assert len(df) == 10
|
||||
assert len(df.columns) == 5
|
||||
|
||||
@pytest.mark.parametrize("suffix", [".ods", ".fods"])
|
||||
def test_header_file_with_cols(self, suffix):
|
||||
|
||||
@pytest.mark.parametrize("suffix", [".ods", ".fods"])
|
||||
def test_header_file_with_cols(suffix: str) -> None:
|
||||
"""Test overwriting haders with column names."""
|
||||
path = rsc / header_file
|
||||
columns = ["One", "Two", "Three", "Four", "Five"]
|
||||
df = read_ods(path.with_suffix(suffix), "Sheet1", columns=columns)
|
||||
|
|
@ -61,9 +63,10 @@ class TestOdsReader:
|
|||
assert len(df) == 10
|
||||
assert len(df.columns) == 5
|
||||
|
||||
@pytest.mark.parametrize("suffix", [".ods", ".fods"])
|
||||
def test_no_header_file_no_cols(self, suffix):
|
||||
|
||||
@pytest.mark.parametrize("suffix", [".ods", ".fods"])
|
||||
def test_no_header_file_no_cols(suffix: str) -> None:
|
||||
"""Test autogeneration of headers with no headers and not column names."""
|
||||
path = rsc / no_header_file
|
||||
df = read_ods(path.with_suffix(suffix), 1, headers=False)
|
||||
|
||||
|
|
@ -71,9 +74,10 @@ class TestOdsReader:
|
|||
assert len(df) == 10
|
||||
assert len(df.columns) == 5
|
||||
|
||||
@pytest.mark.parametrize("suffix", [".ods", ".fods"])
|
||||
def test_no_header_file_with_cols(self, suffix):
|
||||
|
||||
@pytest.mark.parametrize("suffix", [".ods", ".fods"])
|
||||
def test_no_header_file_with_cols(suffix: str) -> None:
|
||||
"""Test reading a file with no headers and passing column names."""
|
||||
path = rsc / no_header_file
|
||||
columns = ["A", "B", "C", "D", "E"]
|
||||
df = read_ods(path.with_suffix(suffix), 1, headers=False, columns=columns)
|
||||
|
|
@ -81,9 +85,10 @@ class TestOdsReader:
|
|||
assert list(df.columns) == columns
|
||||
assert len(df) == 10
|
||||
|
||||
@pytest.mark.parametrize("suffix", [".ods", ".fods"])
|
||||
def test_duplicated_column_names(self, suffix):
|
||||
|
||||
@pytest.mark.parametrize("suffix", [".ods", ".fods"])
|
||||
def test_duplicated_column_names(suffix: str) -> None:
|
||||
"""Test numbering duplicate column names."""
|
||||
path = rsc / duplicated_column_names_file
|
||||
df = read_ods(path.with_suffix(suffix), 1)
|
||||
|
||||
|
|
@ -91,9 +96,10 @@ class TestOdsReader:
|
|||
assert len(df.columns) == 4
|
||||
assert "website.1" in df.columns
|
||||
|
||||
@pytest.mark.parametrize("suffix", [".ods", ".fods"])
|
||||
def test_header_file_col_len(self, suffix):
|
||||
|
||||
@pytest.mark.parametrize("suffix", [".ods", ".fods"])
|
||||
def test_header_file_col_len(suffix: str) -> None:
|
||||
"""Test the correct number of columns is read."""
|
||||
path = rsc / col_len_file
|
||||
df = read_ods(path.with_suffix(suffix), 1)
|
||||
|
||||
|
|
@ -101,18 +107,20 @@ class TestOdsReader:
|
|||
assert len(df) == 10
|
||||
assert len(df.columns) == 5
|
||||
|
||||
@pytest.mark.parametrize("suffix", [".ods", ".fods"])
|
||||
def test_wrong_id_type(self, suffix):
|
||||
|
||||
@pytest.mark.parametrize("suffix", [".ods", ".fods"])
|
||||
def test_wrong_id_type(suffix: str) -> None:
|
||||
"""Verify passing a wrong id type raises an error."""
|
||||
path = rsc / header_file
|
||||
|
||||
with pytest.raises(ValueError) as e_info:
|
||||
read_ods(path.with_suffix(suffix), 1.0)
|
||||
assert e_info.match("Sheet id has to be either `str` or `int`")
|
||||
|
||||
@pytest.mark.parametrize("suffix", [".ods", ".fods"])
|
||||
def test_non_existent_sheet(self, suffix):
|
||||
|
||||
@pytest.mark.parametrize("suffix", [".ods", ".fods"])
|
||||
def test_non_existent_sheet(suffix: str) -> None:
|
||||
"""Verify referencing a non-existent sheet raises an error."""
|
||||
path = rsc / header_file
|
||||
sheet_name = "No_Sheet"
|
||||
|
||||
|
|
@ -120,9 +128,10 @@ class TestOdsReader:
|
|||
read_ods(path.with_suffix(suffix), sheet_name)
|
||||
assert e_info.match(f"There is no sheet named {sheet_name}")
|
||||
|
||||
@pytest.mark.parametrize("suffix", [".ods", ".fods"])
|
||||
def test_missing_header(self, suffix):
|
||||
|
||||
@pytest.mark.parametrize("suffix", [".ods", ".fods"])
|
||||
def test_missing_header(suffix: str) -> None:
|
||||
"""Verify that a missing header is named."""
|
||||
path = rsc / missing_header_file
|
||||
df = read_ods(path.with_suffix(suffix), 1)
|
||||
|
||||
|
|
@ -132,9 +141,10 @@ class TestOdsReader:
|
|||
|
||||
assert df.columns[2] == "unnamed.1"
|
||||
|
||||
@pytest.mark.parametrize("suffix", [".ods", ".fods"])
|
||||
def test_mixed_dtypes(self, suffix):
|
||||
|
||||
@pytest.mark.parametrize("suffix", [".ods", ".fods"])
|
||||
def test_mixed_dtypes(suffix: str) -> None:
|
||||
"""Verify loading a df with mixed types."""
|
||||
path = rsc / mixed_dtypes_file
|
||||
df = read_ods(path.with_suffix(suffix), 1)
|
||||
|
||||
|
|
@ -147,9 +157,10 @@ class TestOdsReader:
|
|||
col_b_types = [type(v) for v in df.B.values]
|
||||
assert str in col_b_types and float in col_b_types
|
||||
|
||||
@pytest.mark.parametrize("suffix", [".ods", ".fods"])
|
||||
def test_skiprows(self, suffix):
|
||||
|
||||
@pytest.mark.parametrize("suffix", [".ods", ".fods"])
|
||||
def test_skiprows(suffix: str) -> None:
|
||||
"""Verify skipping rows works correctly."""
|
||||
path = rsc / skiprows_file
|
||||
df = read_ods(path.with_suffix(suffix), skiprows=2)
|
||||
assert isinstance(df, pd.DataFrame)
|
||||
|
|
@ -157,8 +168,9 @@ class TestOdsReader:
|
|||
assert len(df.columns) == 5
|
||||
assert df.columns.tolist() == ["a", "b", "c", "d", "e"]
|
||||
|
||||
def test_invalid_path(self):
|
||||
|
||||
def test_invalid_path() -> None:
|
||||
"""Verify passing an invalid path raises an error."""
|
||||
path = rsc / "does-not-exist.ods"
|
||||
with pytest.raises(FileNotFoundError, match="does not exist"):
|
||||
read_ods(path)
|
||||
|
|
|
|||
Loading…
Reference in New Issue