Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENH: Codecoverage Test 4 #42

Merged
merged 1 commit into from
Oct 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions radarx/testing/test_data_imd.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)

__all__ = ["fetch_imd_test_data"]
__all__ = ["fetch_imd_test_data", "display_fetched_files"]


def fetch_imd_test_data():
Expand Down Expand Up @@ -53,8 +53,15 @@
return downloaded_files


if __name__ == "__main__":
# Fetch the IMD data and print the paths of downloaded files
def display_fetched_files():
"""
Displays the downloaded file paths by logging them.
"""
files = fetch_imd_test_data()
for file_name, file_path in files.items():
logger.info(f"Local path for {file_name}: {file_path}")


if __name__ == "__main__":
# Display the fetched IMD data file paths
display_fetched_files()

Check warning on line 67 in radarx/testing/test_data_imd.py

View check run for this annotation

Codecov / codecov/patch

radarx/testing/test_data_imd.py#L67

Added line #L67 was not covered by tests
13 changes: 13 additions & 0 deletions tests/test_radarx.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

"""Tests for `radarx` package."""

import radarx
import pytest
from unittest import mock


@pytest.fixture
Expand All @@ -19,3 +21,14 @@ def test_content(response):
"""Sample pytest test function with the pytest fixture as an argument."""
# from bs4 import BeautifulSoup
# assert 'GitHub' in BeautifulSoup(response.content).title.string


def test_version_import_failure():
"""Test to handle the failure of importing radarx.version."""
# Simulate the failure of importing radarx.version
with mock.patch.dict("sys.modules", {"radarx.version": None}):
# Reload radarx to trigger the exception handling in __init__.py
import importlib

importlib.reload(radarx)
assert radarx.__version__ == "999"
26 changes: 25 additions & 1 deletion tests/testing/test_test_timd_data.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pytest
import logging
from radarx.testing.test_data_imd import fetch_imd_test_data
from radarx.testing.test_data_imd import fetch_imd_test_data, display_fetched_files
from pathlib import Path


Expand Down Expand Up @@ -75,5 +75,29 @@ def test_fetch_imd_test_data_error_handling(mocker, capture_logs):
), "An error log should be present when a download fails."


def test_display_fetched_files(mocker, capture_logs):
"""
Test the display_fetched_files function to ensure that it logs the downloaded file paths.
"""
# Mock fetch_imd_test_data to return sample data
mock_files = {
"GOA210515003646-IMD-C.nc": "/path/to/GOA210515003646-IMD-C.nc",
"GOA210515003646-IMD-C.nc.1": "/path/to/GOA210515003646-IMD-C.nc.1",
}
mocker.patch(
"radarx.testing.test_data_imd.fetch_imd_test_data", return_value=mock_files
)

# Call the display_fetched_files function
display_fetched_files()

# Verify that the file paths were logged
for file_name, file_path in mock_files.items():
assert any(
f"Local path for {file_name}: {file_path}" in record.message
for record in capture_logs.records
), f"Log should contain the path for {file_name}"


if __name__ == "__main__":
pytest.main()