Skip to content

Decompose set_increment_times() into one method per phase - #472

Open
adrianseco wants to merge 5 commits into
NASA-PDS:mainfrom
adrianseco:464-decompose-set-increment-times
Open

adrianseco wants to merge 5 commits into
NASA-PDS:mainfrom
adrianseco:464-decompose-set-increment-times

Conversation

@adrianseco

Copy link
Copy Markdown
Contributor

🗒️ Summary

SpiceKernelsCollection.set_increment_times() was split into one private method per phase, and it now only calls them in order and stores the result: _initial_increment_times() picks the first times (from the meta-kernels, then the configuration, then the mission times), _correct_from_previous_bundle() widens them with the latest previous bundle label, and _normalise_increment_times() converts them to the configured date format. The code was moved as it was, so the times, the log messages, their levels and their order are the same as on main, including the partial update when a previous label has a start tag but no stop tag.

The known defects were kept on purpose so that each later fix stays local to one small method: the string comparison of the times before normalisation, the [:-1] that assumes a trailing 'Z', the lexical sort of the previous labels, the 'corrected form previous bundle' typo, and the 'Increment stop time set to' wording used for the start time.

Direct tests were added for each new method and for the order of the calls. The existing set_increment_times() tests were not modified.

⚙️ Test Data and/or Report

Regression tests included: tests/npb/test_classes_collection_kernels.py

Method New tests What they cover
_initial_increment_times 11 meta-kernel coverage (earliest start, latest stop), ignored meta-kernels, configuration start/finish/empty, mission fallback, missing or None times, and the mixed result when a stop time fails after the start was taken
_correct_from_previous_bundle 11 previous start earlier/later/equal, previous finish later, both ends wider, no label, unreadable label, non-UTF-8 label, start tag only (partial update), stop tag only, and the glob pattern
_normalise_increment_times 3 maklabel and infomod2 formats, and no LSK loaded (times kept, warning logged first)
set_increment_times 1 the three phases are called in order, each with the previous result, and the last one is stored
pytest tests/npb/test_classes_collection_kernels.py --cov-branch -q
145 passed, 1 skipped

Name                                                                  Stmts   Miss Branch BrPart  Cover
-------------------------------------------------------------------------------------------------------
src/pds/naif_pds4_bundler/classes/collection/collection_kernels.py      213      0    104      0   100%

Full merge-gate suite (pytest tests/npb/ --cov-branch):
2435 passed, 6 skipped, 1 xfailed, 99% overall coverage

♻️ Related Issues

Fixes #464

The date conversion at the end of set_increment_times() was moved into
_normalise_increment_times(). It takes the two times and returns them
converted, or unchanged with a warning when no leap seconds kernel is
loaded. The times and the log output are the same as before.
The step of widening the increment times with the previous bundle's
interval was moved into _correct_from_previous_bundle(). It takes the
two times and returns them, keeping a corrected start even when the
stop time can't be read from the previous label. The times and the log
output are the same as before.
The choice of the first increment start and finish times was moved into
_initial_increment_times(). It tries the meta-kernels first, then the
configuration, and finally the mission times, and set_increment_times()
now only calls the three steps in order and stores the result. The times
and the log output are the same as before.
The three methods that set_increment_times() now delegates to, and the
order in which it calls them, are tested on their own. The cases cover
the meta-kernel, configuration and mission times, every outcome of
reading the previous bundle label (including a label with only a start
time), and the conversion with and without a leap seconds kernel.
@jdiazdelrio
jdiazdelrio marked this pull request as ready for review November 18, 2026 17:52
@jdiazdelrio
jdiazdelrio requested a review from a team as a code owner November 18, 2026 17:52
@jdiazdelrio
jdiazdelrio requested a review from naif-jpl November 18, 2026 17:52
self.increment_finish = increment_finish
self.increment_start = increment_start

def _initial_increment_times(self) -> tuple[str, str]:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method, and the other two added in this PR, do not have :return: lines (or :param:, where applicable). Please add the input and output documentation to the docstrings.

Comment on lines 219 to 222
@@ -221,6 +221,25 @@ def set_increment_times(self) -> None:
execution. The determined times are stored in ``increment_start`` and
``increment_finish``.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that this method only calls the three phases, the docstring could describe them instead of "the coverage of a given SPK or CK kernel". For example: the initial times come from the meta-kernels, then the configuration, then the mission times; they are widened with the previous bundle's interval; and they are converted to the configured date format.

_Setup(**attrs), make_bundle(), make_kernels())


def _assert_logged(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_assert_logged() checks the levels in full, but each message only for a fragment it contains. The two log-text defects #464 asks to keep are therefore not pinned. Fixing "corrected form previous bundle" to "from", or "Increment stop time set to" to "start" for the start time, still passes every test. ("INFO", "") also matches any INFO message.

Please compare the full messages (level and text, in order), as the other log tests in this file do with messages == [...]. The cases then need the complete texts, including:

  • " Increment stop time set to: <time> as provided from configuration file" for the configured start time;
  • "-- Increment finish corrected form previous bundle.".

The three phase methods and set_increment_times() now describe what
they take and return, and the main docstring walks through the phases.
The tests now compare the whole log, level and text, so a change to
any message wording is caught.
@sonarqubecloud

Copy link
Copy Markdown

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Decompose SpiceKernelsCollection.set_increment_times() into named phases

2 participants