Repository navigation
Decompose KernelList.validate() into named checks - #470
Conversation
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.
| * check that the files are not in the ``bundle_directory``. Files | ||
| that are only raise a warning. |
There was a problem hiding this comment.
Improve the doctoring, for example: "Files that are in the bundle directory only raise a warning."
| # | ||
| # 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 |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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.
| 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]) |
There was a problem hiding this comment.
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.
|



🗒️ Summary
The checks inside
KernelList.validate()have been moved into their own private methods, andvalidate()now only calls them in the order they run. The bad character logging is a short loop and stays invalidate(). 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(newTestKernelListValidateChecksclass, 50 new tests)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