Skip to content

Add CIMRepository open coverage and align _FormatFilenameAsGlob call sites with its return value - #37

Open
kev365 wants to merge 2 commits into
libyal:mainfrom
kev365:wmi-repository-open-coverage
Open

Add CIMRepository open coverage and align _FormatFilenameAsGlob call sites with its return value#37
kev365 wants to merge 2 commits into
libyal:mainfrom
kev365:wmi-repository-open-coverage

Conversation

@kev365

@kev365 kev365 commented Aug 12, 2026

Copy link
Copy Markdown

Motivation

CIMRepository is the entry point for reading a WMI CIM repository, and tests/wmi_repository.py
currently carries # TODO: add tests for CIMRepository. This adds that coverage using the
test_data/cim corpus already in the repository.

Adding a test that calls CIMRepository.Open() also exercises the six _FormatFilenameAsGlob()
call sites, which is where the second half of this change applies.

Current behavior (verified, for reference)

_FormatFilenameAsGlob() returns a single string:

        return "".join(glob_parts)

Six call sites take two values from it:

Line Filename argument
3495 mapping{n}.map
3854 index.btr
3883 (parameter of _OpenMappingFile)
3907 mapping.ver
3928 objects.data
3956 cim.rep

Calling CIMRepository.Open() against test_data/cim at 4917c9b:

ValueError: too many values to unpack (expected 2)
  File "dtformats/wmi_repository.py", line 3883, in _OpenMappingFile
    filename_as_glob, _ = self._FormatFilenameAsGlob(filename)

The existing tests cover IndexBinaryTreeFile, MappingFile and ObjectsDataFile directly, so
this path is not currently reached by the suite.

Proposed change

  1. Take the single returned value at the six call sites.
  2. Add CIMRepositoryTest.testOpenAndClose, using the existing test_data/cim corpus, resolving
    the existing TODO.
class CIMRepositoryTest(test_lib.BaseTestCase):
    """CIM repository tests."""

    def testOpenAndClose(self):
        """Tests the Open and Close functions."""
        test_directory_path = self._GetTestFilePath(["cim"])
        self._SkipIfPathNotExists(test_directory_path)

        test_repository = wmi_repository.CIMRepository()

        test_repository.Open(test_directory_path)

        try:
            self.assertIsNotNone(test_repository.format_version)
        finally:
            test_repository.Close()

Verification

Re-run from a clean working copy against 4917c9b:

Check Result
Diff size 6 changed lines in dtformats/wmi_repository.py; 16 added and 1 removed in tests/wmi_repository.py (the removed line is the # TODO: add tests for CIMRepository comment this resolves)
New test, without the call-site change fails with the ValueError above
New test, with the call-site change passes
python -m unittest tests.wmi_repository 8 of 8
scripts/wmi_repository.py <repository> completes; 1,857 lines of output on a format 2.2 repository

Backward compatibility

No format, API, or output change. _FormatFilenameAsGlob() itself is unchanged; only the
call sites and the test module are touched.

kev365 and others added 2 commits August 11, 2026 19:10
…sites

_FormatFilenameAsGlob() returns a single string. Six call sites in
CIMRepository took two values from it, which is reached when Open() is
called.

Adds CIMRepositoryTest.testOpenAndClose using the existing test_data/cim
corpus, resolving the "TODO: add tests for CIMRepository" note, and takes
the single returned value at the six call sites so that the new test
exercises Open() end to end.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
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.

1 participant