From 26f86db44feb712632d3d86bf2f83d4b083af091 Mon Sep 17 00:00:00 2001 From: veenstrajelmer <60435591+veenstrajelmer@users.noreply.github.com> Date: Thu, 16 Jan 2025 17:02:54 +0100 Subject: [PATCH] Avoid pytest warnings (#1064) * prevent parsing of multiple datetime columns * captured cdsapi warnings --- dfm_tools/observations.py | 7 ++++++- tests/test_download.py | 16 ++++++++++++---- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/dfm_tools/observations.py b/dfm_tools/observations.py index 43ff9f2b..a7b19289 100644 --- a/dfm_tools/observations.py +++ b/dfm_tools/observations.py @@ -682,7 +682,12 @@ def gesla3_ssh_retrieve_data(row, dir_output, time_min=None, time_max=None, with gesla3_zip.open(file_gesla, "r") as f: data = pd.read_csv(f, comment='#', sep="\\s+", names=["date", "time", "sea_level", "qc_flag", "use_flag"], - parse_dates=[[0, 1]], index_col=0) + ) + # set datetimes as index + dates = data.pop("date") + times = data.pop("time") + data_dt = dates + " " + times + data.index = pd.to_datetime(data_dt) # clean up time duplicates data.index.name = 'time' diff --git a/tests/test_download.py b/tests/test_download.py index 215407c1..b2ad0375 100644 --- a/tests/test_download.py +++ b/tests/test_download.py @@ -130,18 +130,22 @@ def test_cds_credentials_oldurl_incorrectkey_rcfile(): cds_apikey_temp = "INCORRECT-APIKEY" cds_set_credentials_rcfile(cds_url_temp, cds_apikey_temp) with pytest.raises(ValueError) as e: - cds_credentials() + with pytest.warns(UserWarning) as w: + cds_credentials() assert "Old CDS URL found" in str(e.value) assert "The CDS/ECMWF apikey file (~/.cdsapirc) was deleted" in str(e.value) + assert "404 Client Error: Not Found for url:" in str(w[0].message) # test cds_url_temp = "https://cds-beta.climate.copernicus.eu/api" cds_apikey_temp = "INCORRECT-APIKEY" cds_set_credentials_rcfile(cds_url_temp, cds_apikey_temp) with pytest.raises(ValueError) as e: - cds_credentials() + with pytest.warns(UserWarning) as w: + cds_credentials() assert "Old CDS URL found" in str(e.value) assert "The CDS/ECMWF apikey file (~/.cdsapirc) was deleted" in str(e.value) + assert "certificate verify failed" in str(w[0].message) # restore credentials file/envvars set_cds_credentials_ifnot_none(cds_url, cds_apikey) @@ -158,17 +162,21 @@ def test_cds_credentials_oldurl_incorrectkey_envvars(): os.environ["CDSAPI_URL"] = "https://cds.climate.copernicus.eu/api/v2" os.environ["CDSAPI_KEY"] = "INCORRECT-APIKEY" with pytest.raises(ValueError) as e: - cds_credentials() + with pytest.warns(UserWarning) as w: + cds_credentials() assert "Old CDS URL found" in str(e.value) assert "The CDS/ECMWF apikey file (~/.cdsapirc) was deleted" in str(e.value) + assert "404 Client Error: Not Found for url:" in str(w[0].message) # test os.environ["CDSAPI_URL"] = "https://cds-beta.climate.copernicus.eu/api" os.environ["CDSAPI_KEY"] = "INCORRECT-APIKEY" with pytest.raises(ValueError) as e: - cds_credentials() + with pytest.warns(UserWarning) as w: + cds_credentials() assert "Old CDS URL found" in str(e.value) assert "The CDS/ECMWF apikey file (~/.cdsapirc) was deleted" in str(e.value) + assert "certificate verify failed" in str(w[0].message) # restore credentials file/envvars set_cds_credentials_ifnot_none(cds_url, cds_apikey)