Skip to content

Commit

Permalink
Merge pull request #42 from syedhamidali/update-imd
Browse files Browse the repository at this point in the history
ENH: Codecoverage Test 4
  • Loading branch information
syedhamidali authored Oct 13, 2024
2 parents 91c940e + 61a0346 commit 1fbd05b
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 4 deletions.
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 @@ def fetch_imd_test_data():
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()
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()

0 comments on commit 1fbd05b

Please sign in to comment.