forked from IMAP-Science-Operations-Center/imap_processing
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor imap_processing.cli.ProcessInstrument (IMAP-Science-Operatio…
…ns-Center#550) * Refactor ProcessInstrument class to have final processing method that calls three overridable methods as part of the process workflow. * add test_cli.py which contains test coverage for imap_processing.cli.py * Apply docstring formatting suggestions from code review Co-authored-by: Matthew Bourque <[email protected]> * CI: Add codecov upload token (IMAP-Science-Operations-Center#554) * Add launch_time parameter to cdf.utils.calc_start_time (IMAP-Science-Operations-Center#552) * Added optional launch_time parameter to calc_start_time so instruments can define their own launch time * Expanded calc_start_time test to use new launch_time parameter * Add a DOI badge to the README (IMAP-Science-Operations-Center#555) * Modify docstrings to use 80 character standard width --------- Co-authored-by: Matthew Bourque <[email protected]> Co-authored-by: Greg Lucas <[email protected]> Co-authored-by: Veronica Martinez <[email protected]>
- Loading branch information
1 parent
bb44a1f
commit df63f07
Showing
2 changed files
with
201 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
"""Tests coverage for imap_processing.cli.""" | ||
|
||
import sys | ||
from unittest import mock | ||
|
||
import pytest | ||
|
||
from imap_processing.cli import Hi, _validate_args, main | ||
|
||
|
||
@mock.patch("imap_processing.cli.Mag") | ||
def test_main(mock_instrument): | ||
"""Test imap_processing.cli.main()""" | ||
test_args = [ | ||
"imap_cli", | ||
"--instrument", | ||
"mag", | ||
"--dependency", | ||
( | ||
'[{"instrument": "mag", ' | ||
'"data_level": "l0", ' | ||
'"descriptor": "sci", ' | ||
'"version": "v001", ' | ||
'"start_date": "20240430"}]' | ||
), | ||
"--data-level", | ||
"l1a", | ||
"--start-date", | ||
"20240430", | ||
"--end-date", | ||
"20240501", | ||
"--version", | ||
"v00-01", | ||
"--upload-to-sdc", | ||
] | ||
with mock.patch.object(sys, "argv", test_args): | ||
# Running without raising an exception is a pass. | ||
# No asserts needed. | ||
main() | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"instrument, data_level, raises_value_error", | ||
[ | ||
("mag", "l0", ""), | ||
("foo", "l0", "foo is not in the supported .*"), | ||
("codice", "l1z", "l1z is not a supported .*"), | ||
], | ||
) | ||
def test_validate_args(instrument, data_level, raises_value_error): | ||
"""Test coverage for imap_processing.cli._validate_args()""" | ||
args = mock.Mock | ||
args.instrument = instrument | ||
args.data_level = data_level | ||
|
||
if raises_value_error: | ||
with pytest.raises(ValueError, match=raises_value_error): | ||
_validate_args(args) | ||
else: | ||
_validate_args(args) | ||
|
||
|
||
@mock.patch("imap_processing.cli.imap_data_access.query") | ||
@mock.patch("imap_processing.cli.imap_data_access.download") | ||
@mock.patch("imap_processing.cli.imap_data_access.upload") | ||
@mock.patch("imap_processing.cli.hi_l1a.hi_l1a") | ||
@mock.patch("imap_processing.cli.write_cdf") | ||
def test_hi(mock_write_cdf, mock_hi_l1a, mock_upload, mock_download, mock_query): | ||
"""Test coverage for cli.Hi class""" | ||
mock_query.return_value = [{"file_path": "/path/to/file0"}] | ||
mock_download.return_value = "file0" | ||
mock_hi_l1a.return_value = ["l1a_file0", "l1a_file1"] | ||
mock_write_cdf.side_effect = ["/path/to/file0", "/path/to/file1"] | ||
|
||
dependency_str = ( | ||
"[{" | ||
"'instrument': 'lo'," | ||
"'data_level': 'l0'," | ||
"'descriptor': 'sci'," | ||
"'version': 'v00-01'," | ||
"'start_date': '20231212'" | ||
"}]" | ||
) | ||
instrument = Hi("l1a", dependency_str, "20231212", "20231213", "v005", True) | ||
instrument.process() | ||
assert mock_query.call_count == 1 | ||
assert mock_download.call_count == 1 | ||
assert mock_hi_l1a.call_count == 1 | ||
assert mock_upload.call_count == 2 |