Repository navigation
Pin the current checksum behaviour with tests - #471
Conversation
Add a test that builds a PDS4 checksum table from a fixed set of entries and compares the written file byte for byte, once with LF and once with CRLF line endings. It fixes the entry order, the two-space separator and the line terminator as they are today.
Add a test that builds a PDS3 checksum table from names that differ only by '_' and '.', and compares the written file byte for byte, with LF and CRLF line endings. It fixes the mkpdssum.pl entry order, the trailing-space padding, and the bytes, record_bytes and file_records values.
Add tests that read a real previous checksum file, in PDS4 and PDS3 with LF and CRLF line endings, and check that its entries are loaded without line endings or name padding. A second test checks the error messages for a line without two fields, a blank line, and an MD5 that is shorter or longer than 32 characters.
Add a test with two files that share an MD5 under different names. It checks that the table keeps both, that the warnings list the shared MD5 with both names, and that nothing raises, in debug mode or not.
Add integration tests, with a real setup and real label files, that check where the checksum takes its times from: only the spice_kernels collection and orbnum labels count, labels listed in the previous checksum count on an increment, generate() keeps the times that set_coverage() found, the mission times are used when there are no coverage labels, and a checksum rebuilt for a previous release uses the labels of that release.
Add tests that record what run_pipeline does with the checksum and its inventory at each of the three places it builds them, and compare the whole sequence. The current PDS4 checksum is added once to the miscellaneous collection before its VID is set, the PDS3 checksum is added once after being labeled, and each past release in the history backfill adds its checksum and its inventory once to its own collection and once to the current one.
Drop the helper that recorded the order of the checksum calls and read the order from the calls each collection mock already keeps. The tests still pin where each checksum and inventory is added and when the VID is set, and now also check that each past checksum is generated from the history of its own release.
The checksum cuts product names at the archive folder using forward slashes, and writes its table in text mode. On Windows the tests gave it backslash names, and every line feed in the table gained a carriage return. The tests now give forward-slash names and expect the bytes the writer leaves on each platform.
The collection is now built before the block that expects the error, so only the product creation can raise there. The generate test now compares the times with the expected values before and after, instead of with a copy of its own result.
The times are now checked one by one against their expected values, before and after the checksum file is written, in the same style as the other tests of the file.
jdiazdelrio
left a comment
There was a problem hiding this comment.
The add/VID calls and the generate/register/label calls are pinned separately, so nothing pins how they interleave. #463 asks for the order of "what is registered, labelled and added". As it stands, moving add(checksum) before generate() in the PDS3 branch, or the backfill adds before the label, still passes every test.
Please record all the calls of each site in one sequence and assert it in full:
- PDS4 current release (
test_current_checksum_added_before_collection_vid):add(checksum)→set_collection_vid()→set_coverage()→generate()→register_product(checksum)→ChecksumPDS4Label. - PDS4 history backfill (
test_past_release_products_added_to_both_collections), for each past release:generate(history=...)→register_product→ChecksumPDS4Label→addto the release collection →addto the current collection →set_collection_vid()on the release collection. - PDS3 (
test_pds3_checksum_added_once_to_collection):generate()→register_product(checksum)→ChecksumPDS3Label→add(checksum).
One way to do it is to attach the collection mocks, the checksum mocks and register_product to one parent mock with attach_mock() and compare its mock_calls. Another is to append to the same calls list the existing *_registered_between_generate_and_label tests use. The existing tests can stay as they are.
The calls that generate, register, label and add the checksum are now recorded in one list and compared in full. This is done for the current PDS4 release, for each past release rebuilt from the history, and for PDS3, so moving any of those calls relative to the others now fails a test.
|



🗒️ Summary
Tests were added to record how the checksum code behaves today, so the restructuring planned for it can show that it changes nothing. Nothing under
src/was touched, and where the current behaviour looks wrong, the test keeps it as it is.Two oddities turned up along the way and were left for later: the check for duplicate MD5 sums never matches, and on Windows the table lines end in CR CR LF.
⚙️ Test Data and/or Report
Regression tests included:
test_classes_product_checksum.py,test_pipeline_npb.pyand the newintegration/test_checksum_coverage.py(24 new test cases, no existing test modified):test_pds4_table_bytesmkpdssum.plorder, padding and size valuestest_pds3_table_bytes_and_countstest_previous_checksum_file_is_loadedtest_corrupted_previous_checksum_file_raisestest_duplicate_md5_is_warned_and_does_not_raisetest_only_coverage_labels_set_the_timestest_previous_checksum_entries_set_the_timesgenerate()keeps whatset_coverage()foundtest_generate_keeps_the_times_of_set_coveragetest_mission_times_are_used_without_coverage_labelstest_history_checksum_uses_the_labels_of_its_releasetest_current_checksum_added_before_collection_vidtest_past_release_products_added_to_both_collectionstest_pds3_checksum_added_once_to_collectionThe tests were also run against deliberately broken versions of the code (a plain sort for PDS3, labels counted for the times that should not be, an add removed from the pipeline, and similar), and every change that altered the behaviour made at least one test fail.
♻️ Related Issues
Fixes #463