|
11 | 11 | TEST_DIRECTORY = Path(__file__).parent / "test_directory"
|
12 | 12 | FILE_DIR_TEST_DIRECTORY = TEST_DIRECTORY / "file_dir"
|
13 | 13 |
|
| 14 | +PANDAS_READ_METHODS_MAP = { |
| 15 | + ".csv": "read_csv", ".xlsx": "read_excel", |
| 16 | + ".html": "read_html", ".json": "read_json", |
| 17 | +} |
| 18 | + |
14 | 19 | # Test parameters for individual functions defined below
|
15 | 20 |
|
16 | 21 | PARSE_QUERY_FUNC_PARAMS = [
|
|
32 | 37 | (3, FILE_DIR_TEST_DIRECTORY / "reports", True),
|
33 | 38 | ]
|
34 | 39 |
|
| 40 | +EXPORT_FILE_TEST_PARAMS = [ |
| 41 | + "export.csv", "output.xlsx", "records.html", "save.json" |
| 42 | +] |
| 43 | + |
| 44 | +# Sample dataframe for testing `tools.export_to_file` function. |
| 45 | + |
| 46 | +SAMPLE_EXPORT_FILE_DATA = pd.DataFrame( |
| 47 | + {2023: [87, 95, 98, 82, 84], 2024: [91, 93, 98, 87, 81]} |
| 48 | +) |
| 49 | + |
35 | 50 | # Test results for individual functions defined below
|
36 | 51 |
|
37 | 52 | PARSE_QUERY_TEST_RESULTS = [
|
@@ -104,3 +119,17 @@ def test_get_directories_function(ctr: int, path: Path, recur: bool) -> None:
|
104 | 119 | tools.get_directories(path, recur),
|
105 | 120 | read_tests_hdf(f"/function/get_directories/test{ctr}"),
|
106 | 121 | )
|
| 122 | + |
| 123 | + |
| 124 | +@pytest.mark.parametrize("file", EXPORT_FILE_TEST_PARAMS) |
| 125 | +def test_file_export_function( |
| 126 | + file: str, data: pd.DataFrame = SAMPLE_EXPORT_FILE_DATA |
| 127 | +) -> None: |
| 128 | + """Tests the `tools.export_to_file` function with different file formats.""" |
| 129 | + |
| 130 | + path: Path = TEST_DIRECTORY / file |
| 131 | + |
| 132 | + tools.export_to_file(data, path) |
| 133 | + assert path.is_file() |
| 134 | + |
| 135 | + path.unlink() |
0 commit comments