Skip to content

Commit

Permalink
fix: great expectations unit tests referring to deprecated method (#1558
Browse files Browse the repository at this point in the history
)

* fix: ge unit tests refering to deprecated method

* change cache_file to use requests instead of urllib

* fix(linting): code formatting

* requests response raise for status

* fix(linting): code formatting

* change read to content

* use cache_file to download zipfile

* fix(linting): code formatting

---------

Co-authored-by: Luís Portela Afonso <luis.portela@ydata.ai>
Co-authored-by: Azory YData Bot <azory@ydata.ai>
  • Loading branch information
3 people committed Mar 18, 2024
1 parent 53dd7cb commit 8d428f2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 13 deletions.
16 changes: 7 additions & 9 deletions src/ydata_profiling/utils/cache.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
"""Dataset cache utility functions"""
import zipfile
from pathlib import Path
from urllib import request

from requests import get as get_file

from ydata_profiling.utils.paths import get_data_path

Expand All @@ -24,8 +25,10 @@ def cache_file(file_name: str, url: str) -> Path:

# If not exists, download and create file
if not file_path.exists():
response = request.urlopen(url)
file_path.write_bytes(response.read())
response = get_file(url, allow_redirects=True)
response.raise_for_status()

file_path.write_bytes(response.content)

return file_path

Expand All @@ -42,16 +45,11 @@ def cache_zipped_file(file_name: str, url: str) -> Path:
"""

data_path = get_data_path()
data_path.mkdir(exist_ok=True)

file_path = data_path / file_name

# If not exists, download and create file
if not file_path.exists():
response = request.urlopen(url)

tmp_path = data_path / "tmp.zip"
tmp_path.write_bytes(response.read())
tmp_path = cache_file("tmp.zip", url)

with zipfile.ZipFile(tmp_path, "r") as zip_file:
zip_file.extract(file_path.name, data_path)
Expand Down
8 changes: 4 additions & 4 deletions tests/unit/test_ge_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def test_to_expectations_suite_context_save_and_build_data_docs(mod, context, df
mod.data_context.DataContext.assert_not_called()
mod.dataset.PandasDataset.assert_called_once()

context.create_expectation_suite.assert_called_once()
context.add_expectation_suite.assert_called_once()
context.save_expectation_suite.assert_called_once()
context.build_data_docs.assert_called_once()
context.open_data_docs.assert_called_once()
Expand All @@ -60,7 +60,7 @@ def test_to_expectations_suite_context_no_save_and_build_data_docs(mod, context,
mod.data_context.DataContext.assert_not_called()
mod.dataset.PandasDataset.assert_called_once()

context.create_expectation_suite.assert_called_once()
context.add_expectation_suite.assert_called_once()
context.save_expectation_suite.assert_called_once()
context.build_data_docs.assert_called_once()
context.open_data_docs.assert_called_once()
Expand All @@ -78,7 +78,7 @@ def test_to_expectations_suite_context_no_save_and_no_build_data_docs(mod, conte
mod.data_context.DataContext.assert_not_called()
mod.dataset.PandasDataset.assert_called_once()

context.create_expectation_suite.assert_called_once()
context.add_expectation_suite.assert_called_once()
context.save_expectation_suite.assert_not_called()
context.build_data_docs.assert_not_called()
context.open_data_docs.assert_not_called()
Expand All @@ -92,7 +92,7 @@ def test_to_expectations_suite_title(context, df):
run_validation=False,
)

context.create_expectation_suite.assert_called_once_with(
context.add_expectation_suite.assert_called_once_with(
"expectations-dataset", overwrite_existing=True
)

Expand Down

0 comments on commit 8d428f2

Please sign in to comment.