|
| 1 | +from unittest.mock import MagicMock, patch |
| 2 | + |
| 3 | +from rgc.utils.data import celestial_capture |
| 4 | + |
| 5 | + |
| 6 | +@patch("rgc.utils.data.SkyView") |
| 7 | +@patch("rgc.utils.data.Path") |
| 8 | +def test_celestial_capture(mock_path, mock_skyview): |
| 9 | + # Mock SkyView.get_images method |
| 10 | + mock_image = MagicMock() |
| 11 | + mock_image[0].header = MagicMock() |
| 12 | + mock_image[0].header.__getitem__.return_value = "Sample comment" |
| 13 | + mock_image[0].header.remove = MagicMock() |
| 14 | + mock_image[0].header.add_comment = MagicMock() |
| 15 | + mock_image.writeto = MagicMock() |
| 16 | + mock_skyview.get_images.return_value = [mock_image] |
| 17 | + |
| 18 | + # Mock Path functionality |
| 19 | + mock_path_instance = MagicMock() |
| 20 | + mock_path_instance.parent = "mock_folder" |
| 21 | + mock_path.return_value = mock_path_instance |
| 22 | + |
| 23 | + # Call the function |
| 24 | + celestial_capture("DSS2 Red", 10.684, 41.269, "test_image.fits") |
| 25 | + |
| 26 | + # Verify that SkyView.get_images was called with correct parameters |
| 27 | + mock_skyview.get_images.assert_called_once_with( |
| 28 | + position="10.684, 41.269", survey="DSS2 Red", coordinates="J2000", pixels=(150, 150) |
| 29 | + ) |
| 30 | + |
| 31 | + # Verify that image.writeto was called with correct filename |
| 32 | + mock_image.writeto.assert_called_once_with("test_image.fits", overwrite=True) |
| 33 | + |
| 34 | + # Verify Path.mkdir was called to create directories |
| 35 | + mock_path_instance.mkdir.assert_called_once_with(parents=True, exist_ok=True) |
| 36 | + |
| 37 | + # Verify header methods were called |
| 38 | + mock_image[0].header.remove.assert_called_once_with("comment", "Sample comment", True) |
| 39 | + mock_image[0].header.add_comment.assert_called_once_with("Sample comment") |
0 commit comments