Skip to content

Decompose KernelList.validate() into named checks - #470

Merged
jdiazdelrio merged 11 commits into
NASA-PDS:mainfrom
adrianseco:462-decompose-kernel-list-validate
Nov 18, 2026
Merged

jdiazdelrio merged 11 commits into
NASA-PDS:mainfrom
adrianseco:462-decompose-kernel-list-validate

Conversation

@adrianseco

@adrianseco adrianseco commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

🗒️ Summary

The checks inside KernelList.validate() have been moved into their own private methods, and validate() now only calls them in the order they run. The bad character logging is a short loop and stays in validate(). The comparison with the previous release list used to read a variable left over from the duplicate check, and now receives the sorted release lists as an argument. The two PDS3 blocks were merged into a single method, and the docstring now lists each check once, in the order the code runs them.

Nothing changes in behavior: the log messages, their order and the exceptions raised are the same as before, and the known defects were left as they were. Each new method has its own tests, and the existing validate() tests were not modified.

⚙️ Test Data and/or Report

Regression tests included: test_classes_kernel_list.py (new TestKernelListValidateChecks class, 50 new tests)

pytest tests/npb/test_classes_kernel_list.py --cov=pds.naif_pds4_bundler.classes.list --cov-branch -q
230 passed, 1 skipped

Name                                              Stmts   Miss Branch BrPart  Cover
-----------------------------------------------------------------------------------
src/pds/naif_pds4_bundler/classes/list.py           548      0    266      0   100%

Full merge-gate suite (pytest --cov-branch --cov-fail-under=80 -n auto):
2443 passed, 6 skipped, 1 xfailed, 99.76% overall coverage

♻️ Related Issues

Fixes #462

validate() kept the file open for its whole body, but only the parsing
call reads from it. Parse first, close the file, and let the checks work
on the parsed entries. The rest of the body moves one indentation level
out; behaviour is unchanged.
The bad-character logging, entry-count, plan-membership and duplicate
checks are now private methods that take the parsed entries, and
validate() calls them in order. Log messages and exceptions are
unchanged, including the bare Exception raised when the counts differ.
Each method has direct tests.
The kernels-directory and bundle-area checks become their own methods,
moved over as they were, including the known 'present' flag defect and
its TODO. The new tests pin both outcomes of that defect, so it cannot
change unnoticed.
The two PDS3-only blocks, one that displays the MAKLABEL_OPTIONS used and
one that checks them against the mission template, now live in a single
method that returns early for PDS4. This removes the cleaned option list
that the first block used to leave behind for the second. Log order,
the KeyError for a template without options and the tolerance of N/A are
unchanged, and each is covered by a test.
The duplicate check across the release kernel lists and the comparison
with the previous release list are now separate methods. The first
returns the sorted list paths and the second receives them, so the
comparison no longer reads a variable left behind by an earlier block.
Messages, log order and the handling of a missing or unreadable list are
unchanged, and each outcome of the comparison is covered by a test.
The list named the duplicate check twice, put the bad-character check
last although it runs first, and misspelled MAKLABEL_OPTIONS. It now has
one entry per check in the order the code runs them, and says which
checks only warn and which apply to PDS3.
The expected paths in the release history tests were written with a
forward slash, which only matches on Linux. They are now built with
pathlib, so they also match on Windows.
@jdiazdelrio
jdiazdelrio marked this pull request as ready for review November 18, 2026 08:39
@jdiazdelrio
jdiazdelrio requested a review from a team as a code owner November 18, 2026 08:39
@jdiazdelrio
jdiazdelrio self-requested a review November 18, 2026 08:39
Comment on lines +424 to +425
* check that the files are not in the ``bundle_directory``. Files
that are only raise a warning.

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.

Improve the doctoring, for example: "Files that are in the bundle directory only raise a warning."

Comment on lines +442 to +446
#
# Check that the list has no bad characters.
# This does not raise an error message but does not stop NPB.
# We add kernels to compare plan and list and to look
# for duplicates.
#
errors = self._check_badchar(list_path)
if errors:
ker_in_list = entries.files

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.

I would remove ker_in_list = entries.files and its "We add kernels to compare plan and list…" comment, and pass entries.files directly. The comment described the old inline code.

"""
list_path = self.setup.working_directory + os.sep + self.list_name

self._check_badchar_in_list(list_path)

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.

I think it is better to remove the _check_badchar_in_list wrapper: put the loop back in validate()and delete test_check_badchar_in_list. The bad-character logging stays tested through the existing TestKernelListValidate fixture, which patches _check_badchar.

Comment thread tests/npb/test_classes_kernel_list.py Outdated
Comment on lines +1858 to +1874
def test_check_release_history(self, caplog, tmp_path, kernel_list, files,
expectation, added, tail, names) -> None:
working = tmp_path / 'working'
for name, content in files.items():
(working / name).write_bytes(content)
header = [('INFO', '-- Checking for duplicates in complete kernel'
' list:')]
result = None

with expectation:
result = kernel_list._check_release_history()

adding = [('INFO', f' Adding {working / name} in check.')
for name in added]
assert [(r.levelname, r.getMessage())
for r in caplog.records] == header + adding + tail
assert result == (names and [str(working / name) for name in names])

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.

In this test case, result == (names and [...]) uses None to mean "raised" and [] to mean "no lists". Splitting the two cases, or adding a one-line comment, would make that easier to read.

In the validate() docstring, the bullet about files in the bundle
directory was changed from "Files that are only raise a warning" to
"Files that are in the bundle directory only raise a warning".
In validate(), the ker_in_list alias and its comment were removed, and
the four checks that use the listed kernels now receive entries.files.
In validate(), the loop that logs the bad characters was moved back
from _check_badchar_in_list(), which was removed together with its test.
The logging is still covered by the validate() tests.
test_check_release_history was divided in two: one test for the lists
that are read and returned, and another for the cases that raise. The
expected log lines are now built by a small helper, and the test no
longer needs None to mean that the method raised.
@sonarqubecloud

Copy link
Copy Markdown

@jdiazdelrio jdiazdelrio added the Refactor Used for refactoring code and test cases label Nov 18, 2026
@jdiazdelrio
jdiazdelrio merged commit dfb5bb8 into NASA-PDS:main Nov 18, 2026
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Refactor Used for refactoring code and test cases

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Decompose KernelList.validate() into named checks

3 participants