Skip to content

Commit

Permalink
Add test coverage for time kernels only use of ensure_spice
Browse files Browse the repository at this point in the history
Add test coverage for ensure_spice failure -> SpiceyError
  • Loading branch information
subagonsouth committed Aug 7, 2024
1 parent 136d485 commit c201889
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
6 changes: 3 additions & 3 deletions imap_processing/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ def furnish_sclk(spice_test_data_path):
spice.kclear()


@pytest.fixture(scope="session")
def use_test_metakernel(tmpdir_factory, monkeypatch_session, spice_test_data_path):
@pytest.fixture()
def use_test_metakernel(tmpdir_factory, monkeypatch, spice_test_data_path):
"""For the whole test session, set the SPICE_METAKERNEL environment variable
Prime the test metakernel by creating it from the template metakernel
(allows using absolute paths on any dev system)"""
Expand Down Expand Up @@ -132,6 +132,6 @@ def get_test_kernels_to_load():
metakernel = metakernel_path.join("imap_2024_v001.tm")
kernels_to_load = get_test_kernels_to_load()
make_metakernel_from_kernels(metakernel, kernels_to_load)
monkeypatch_session.setenv("SPICE_METAKERNEL", str(metakernel))
monkeypatch.setenv("SPICE_METAKERNEL", str(metakernel))
yield str(metakernel)
spice.kclear()
15 changes: 15 additions & 0 deletions imap_processing/tests/spice/test_kernels.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import pytest
import spiceypy as spice
from spiceypy.utils.exceptions import SpiceyError

from imap_processing.spice import kernels

Expand Down Expand Up @@ -46,3 +47,17 @@ def double_wrap_et2utc_tk_only(et, fmt, prec):
def test_ensure_spice_emus_mk_path(func, use_test_metakernel):
"""Test functionality of ensure spice with SPICE_METAKERNEL set"""
assert func(577365941.184, "ISOC", 3) == "2018-04-18T23:24:31.998"


def test_ensure_spice_time_kernels():
"""Test functionality of ensure spice with timekernels set"""
wrapped = kernels.ensure_spice(spice.et2utc, time_kernels_only=True)
with pytest.raises(NotImplementedError):
_ = wrapped(577365941.184, "ISOC", 3) == "2018-04-18T23:24:31.998"


def test_ensure_spice_key_error():
"""Test functionality of ensure spice with timekernels set"""
wrapped = kernels.ensure_spice(spice.et2utc)
with pytest.raises(SpiceyError):
_ = wrapped(577365941.184, "ISOC", 3) == "2018-04-18T23:24:31.998"

0 comments on commit c201889

Please sign in to comment.