Skip to content

Commit

Permalink
chore: add depreciation warning, and update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
andy blair committed Sep 25, 2024
1 parent cca2083 commit d4c44d1
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 22 deletions.
11 changes: 9 additions & 2 deletions nyx_client/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"""Module that manages individual Nyx Data."""

import logging
import warnings

import requests

Expand Down Expand Up @@ -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()
11 changes: 0 additions & 11 deletions test/test_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
22 changes: 13 additions & 9 deletions test/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
),
]

Expand All @@ -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"

Expand All @@ -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
Expand Down

0 comments on commit d4c44d1

Please sign in to comment.