From d4c44d13818d943c46a65da40175524e6157c9d7 Mon Sep 17 00:00:00 2001 From: andy blair Date: Fri, 20 Sep 2024 22:30:49 +0100 Subject: [PATCH] chore: add depreciation warning, and update tests --- nyx_client/data.py | 11 +++++++++-- test/test_data.py | 11 ----------- test/test_utils.py | 22 +++++++++++++--------- 3 files changed, 22 insertions(+), 22 deletions(-) diff --git a/nyx_client/data.py b/nyx_client/data.py index 4fd189e..e273fd9 100644 --- a/nyx_client/data.py +++ b/nyx_client/data.py @@ -15,6 +15,7 @@ """Module that manages individual Nyx Data.""" import logging +import warnings import requests @@ -152,11 +153,17 @@ def as_bytes(self) -> bytes | None: ) def download(self) -> str | None: - """DEPRICATED: Download the content of the data as as string. + """Download the content of the data as a string. This method attempts to download the content from the data's URL. Returns: - The downloaded content as string or None, if the download fails. + The downloaded content as a string or None, if the download fails. + + .. deprecated:: 0.2.0 + Use `as_string()` or `as_bytes()` instead. """ + warnings.warn( + "Will be removed in 0.2.0 Use as_string() or as bytes() instead", DeprecationWarning, stacklevel=0 + ) return self.as_string() diff --git a/test/test_data.py b/test/test_data.py index ca8ba88..35d7003 100644 --- a/test/test_data.py +++ b/test/test_data.py @@ -62,17 +62,6 @@ def test_data_download(requests_mock, mock_data_details): content = data.as_string() assert content == "Test Content" - assert data._content == "Test Content" - - -def test_data_download_cached(mocker, mock_data_details): - mock_urlopen = mocker.patch("urllib.request.urlopen") - - data = Data(**mock_data_details) - data._content = "Cached Content" - content = data.as_string() - assert content == "Cached Content" - mock_urlopen.assert_not_called() def test_nyx_data_download_failure(requests_mock, mock_data_details): diff --git a/test/test_utils.py b/test/test_utils.py index e3de827..7cf3c72 100644 --- a/test/test_utils.py +++ b/test/test_utils.py @@ -10,40 +10,44 @@ @pytest.fixture def sample_csv_content(): - return """ + return bytes( + """ id,name,value 1,Alice,100 2,Bob,200 3,Charlie,300 - """ + """, + encoding="utf-8", + ) @pytest.fixture def sample_csv_content_2(): - return """ + return bytes( + """ id,name,value 1,Andy,1000 2,Conal,10 3,Phil,300 - """ + """, + encoding="utf-8", + ) @pytest.fixture -def sample_data(sample_csv_content, sample_csv_content_2): +def sample_data(): return [ Data( access_url="http://example.com/1", title="Test Data 1", org="TestOrg", mediaType="http://www.iana.org/assignments/media-types/text/csv", - content=sample_csv_content, ), Data( access_url="http://example.com/2", title="Test Data 2", org="TestOrg", mediaType="http://www.iana.org/assignments/media-types/text/csv", - content=sample_csv_content_2, ), ] @@ -60,7 +64,7 @@ def test_dataset_as_db_empty_list(): def test_dataset_as_db_with_data(sample_data, sample_csv_content): - with patch.object(Data, "download", return_value=sample_csv_content): + with patch.object(Data, "as_bytes", return_value=sample_csv_content): engine = Parser.data_as_db(sample_data) assert engine is not None, "Engine should not be None" @@ -80,7 +84,7 @@ def test_dataset_as_vectors(): Data(access_url="http://example.com/2", title="Test Data 2", org="TestOrg", mediaType="text/plain"), ] - with patch.object(Data, "download", side_effect=["This is a test content.", "Another test content here."]): + with patch.object(Data, "as_string", side_effect=["This is a test content.", "Another test content here."]): parser.data_as_vectors(data, chunk_size=4) assert parser.vectors is not None