From 61a03463ae3802fd507e93cf11d47972b7bbd734 Mon Sep 17 00:00:00 2001 From: syedhamidali Date: Sun, 13 Oct 2024 19:28:52 -0400 Subject: [PATCH] ENH: Codecoverage Test 4 --- radarx/testing/test_data_imd.py | 13 ++++++++++--- tests/test_radarx.py | 13 +++++++++++++ tests/testing/test_test_timd_data.py | 26 +++++++++++++++++++++++++- 3 files changed, 48 insertions(+), 4 deletions(-) diff --git a/radarx/testing/test_data_imd.py b/radarx/testing/test_data_imd.py index b375c8e..4df8ee8 100644 --- a/radarx/testing/test_data_imd.py +++ b/radarx/testing/test_data_imd.py @@ -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(): @@ -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() diff --git a/tests/test_radarx.py b/tests/test_radarx.py index c3ac875..073c2aa 100644 --- a/tests/test_radarx.py +++ b/tests/test_radarx.py @@ -2,7 +2,9 @@ """Tests for `radarx` package.""" +import radarx import pytest +from unittest import mock @pytest.fixture @@ -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" diff --git a/tests/testing/test_test_timd_data.py b/tests/testing/test_test_timd_data.py index 8682d67..e813f78 100644 --- a/tests/testing/test_test_timd_data.py +++ b/tests/testing/test_test_timd_data.py @@ -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 @@ -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()