Skip to content

Conversation

@pressler-vsc
Copy link
Contributor

Description

Testing with v0.5.0 uncovered a bug where calling .load() with a NITF with an XML_DATA_CONTENT DES would not properly load all of the user-defined DES subheader fields.

New test fails in main
$ JBPY_JITC_QUICKLOOK_DIR=/host_shared/JITC_QuickLook_NITF/Quick-Look-Set-v2023.11.30 pytest test/test_jbpy.py::test_roundtrip_jitc_quicklook
=========================================================================================================================================== test session starts ===========================================================================================================================================
platform linux -- Python 3.14.0, pytest-8.4.2, pluggy-1.6.0
rootdir: /home/vscuser/git/glweb/software/third-party/jbpy
configfile: pyproject.toml
collected 109 items                                                                                                                                                                                                                                                                                       

test/test_jbpy.py ..........................................................................................F..................                                                                                                                                                                     [100%]

================================================================================================================================================ FAILURES =================================================================================================================================================
________________________________________________________________________________________________________________________________ test_roundtrip_jitc_quicklook[filename90] ________________________________________________________________________________________________________________________________

filename = PosixPath('/host_shared/JITC_QuickLook_NITF/Quick-Look-Set-v2023.11.30/2. Data Segments/Test Files/NITF_IMG_POS_08.ntf'), tmp_path = PosixPath('/data/tmp/pytest-of-vscuser/pytest-495/test_roundtrip_jitc_quicklook_90')

    @pytest.mark.skipif(
        "JBPY_JITC_QUICKLOOK_DIR" not in os.environ,
        reason="requires JITC Quick-Look data",
    )
    @pytest.mark.parametrize("filename", test.utils.find_jitcs_test_files())
    def test_roundtrip_jitc_quicklook(filename, tmp_path):
        ntf = jbpy.Jbp()
        with filename.open("rb") as file:
            ntf.load(file)
    
        copy_filename = tmp_path / "copy.nitf"
        with copy_filename.open("wb") as fd:
            ntf.dump(fd)
    
        ntf2 = jbpy.Jbp()
        with copy_filename.open("rb") as file:
            ntf2.load(file)
    
        assert ntf == ntf2
    
        file_components_to_compare = [ntf["FileHeader"]]
        for segtype in list(ntf.values())[1:]:
            file_components_to_compare.extend(x["subheader"] for x in segtype)
        for component in file_components_to_compare:
            with filename.open("rb") as f_orig, copy_filename.open("rb") as f_copy:
                offset = component.get_offset()
                size = component.get_size()
                f_orig.seek(offset)
                bytes_orig = f_orig.read(size)
                f_copy.seek(offset)
                bytes_copy = f_copy.read(size)
>               assert bytes_orig == bytes_copy
E               AssertionError: assert b'DEXML_DATA_...             ' == b'DEXML_DATA_...             '
E                 
E                 At index 200 diff: b'9' != b'0'
E                 Use -v to get more diff

test/test_jbpy.py:41: AssertionError
========================================================================================================================================= short test summary info =========================================================================================================================================
FAILED test/test_jbpy.py::test_roundtrip_jitc_quicklook[filename90] - AssertionError: assert b'DEXML_DATA_...             ' == b'DEXML_DATA_...             '
===================================================================================================================================== 1 failed, 108 passed in 10.19s ======================================================================================================================================

The cause was traced to a reassignment to a jbpy.core.ComponentCollection._children list, which happened while the list was being iterated over by the load. The fix is to modify the list in place rather than reassign so that the iteration continues appropriately. To encourage this behavior, a typing.Final annotation was added

JITC tests pass
(jbpy) 09:16:21 [jbpy] (1083)$ JBPY_JITC_QUICKLOOK_DIR=/host_shared/JITC_QuickLook_NITF/Quick-Look-Set-v2023.11.30 pytest 
=========================================================================================================================================== test session starts ===========================================================================================================================================
platform linux -- Python 3.14.0, pytest-8.4.2, pluggy-1.6.0
rootdir: /home/vscuser/git/glweb/software/third-party/jbpy
configfile: pyproject.toml
collected 528 items                                                                                                                                                                                                                                                                                       

test/des_subheader/test_xml_data_content.py .                                                                                                                                                                                                                                                       [  0%]
test/test_core.py ...................................                                                                                                                                                                                                                                               [  6%]
test/test_image_data.py ......................                                                                                                                                                                                                                                                      [ 10%]
test/test_jbpdump.py ..                                                                                                                                                                                                                                                                             [ 11%]
test/test_jbpinfo.py .............................................................................................................................................................................................................................................................................. [ 62%]
...........................................................                                                                                                                                                                                                                                         [ 73%]
test/test_jbpy.py ............................................................................................................................                                                                                                                                                      [ 97%]
test/tre/test_exopta.py .                                                                                                                                                                                                                                                                           [ 97%]
test/tre/test_j2klra.py ..                                                                                                                                                                                                                                                                          [ 97%]
test/tre/test_prjpsb.py .                                                                                                                                                                                                                                                                           [ 97%]
test/tre/test_regptb.py .                                                                                                                                                                                                                                                                           [ 98%]
test/tre/test_rpc00b.py ..                                                                                                                                                                                                                                                                          [ 98%]
test/tre/test_tre.py .......                                                                                                                                                                                                                                                                        [ 99%]
test/tre/test_use00a.py .                                                                                                                                                                                                                                                                           [100%]

===================================================================================================================================== 528 passed in 144.55s (0:02:24) =====================================================================================================================================

@pressler-vsc pressler-vsc merged commit 5c6804b into main Dec 17, 2025
5 checks passed
@pressler-vsc pressler-vsc deleted the bugfix/des-subheader-load branch December 17, 2025 19:26
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.

4 participants