|
29 | 29 | [[1, 2], [3, np.nan], [np.nan, 6]], columns=["a", "b"], index=index_preprocess |
30 | 30 | ) |
31 | 31 |
|
| 32 | +urllink = "https://archive.ics.uci.edu/ml/machine-learning-databases/00501/" |
| 33 | +zipname = "PRSA2017_Data_20130301-20170228" |
| 34 | + |
| 35 | + |
| 36 | +# @pytest.mark.parametrize("zipname, urllink", [(zipname, urllink)]) |
| 37 | +# def test_utils_data_download_data(zipname: str, urllink: str, mocker: MockerFixture) -> None: |
| 38 | +# mocker.patch("urllib.request.urlretrieve") |
| 39 | +# mocker.patch("zipfile.ZipFile") |
| 40 | +# list_df_result = data.download_data(zipname, urllink) |
| 41 | + |
32 | 42 |
|
33 | 43 | @pytest.mark.parametrize("name_data", ["Beijing", "Artificial", "Bug"]) |
34 | 44 | def test_utils_data_get_data(name_data: str, mocker: MockerFixture) -> None: |
@@ -67,11 +77,15 @@ def test_utils_data_add_holes(df: pd.DataFrame) -> None: |
67 | 77 |
|
68 | 78 |
|
69 | 79 | @pytest.mark.parametrize("name_data", ["Beijing"]) |
70 | | -def test_utils_data_get_data_corrupted(name_data: str) -> None: |
| 80 | +def test_utils_data_get_data_corrupted(name_data: str, mocker: MockerFixture) -> None: |
| 81 | + mock_download = mocker.patch("qolmat.utils.data.download_data", return_value=[df]) |
| 82 | + mocker.patch("qolmat.utils.data.preprocess_data", return_value=df_preprocess) |
71 | 83 | df_out = data.get_data_corrupted() |
72 | | - size_df_out = df_out.shape |
73 | | - n = size_df_out[0] * size_df_out[1] |
74 | | - np.testing.assert_allclose(df_out.isna().sum().sum() / n, 0.2, atol=0.1) |
| 84 | + df_result = pd.DataFrame( |
| 85 | + [[1, 2], [np.nan, np.nan], [np.nan, 6]], columns=["a", "b"], index=index_preprocess |
| 86 | + ) |
| 87 | + assert mock_download.call_count == 1 |
| 88 | + pd.testing.assert_frame_equal(df_result, df_out) |
75 | 89 |
|
76 | 90 |
|
77 | 91 | @pytest.mark.parametrize("df", [df_preprocess]) |
|
0 commit comments