Skip to content

Fix the path cache test fakes and cover the listing sizes they missed - #309

Merged
kandrosov merged 1 commit into
cms-flaf:mainfrom
kandrosov:fix-path-cache-test-fakes
Aug 27, 2026
Merged

Fix the path cache test fakes and cover the listing sizes they missed#309
kandrosov merged 1 commit into
cms-flaf:mainfrom
kandrosov:fix-path-cache-test-fakes

Conversation

@kandrosov

Copy link
Copy Markdown
Contributor

Problem

test/test_path_cache.py fails on main — 9 of its 10 tests:

AttributeError: 'Entry' object has no attribute 'is_dir'                     RunKit/law_gfal.py:511
AttributeError: 'FakeGFALFileInterface' object has no attribute 'listing_sizes'  RunKit/law_gfal.py:508

#307 added listdir_info, _cache_listing_sizes and self.listing_sizes to
GFALFileInterface, reading entry.is_dir and entry.size off a listing. The test file, added
in #304, models a listing entry as namedtuple("Entry", ["name"]) and builds its fake interface
by assigning voms_token / path_cache / verbose by hand instead of calling the real
__init__ — so neither the new attribute nor the new fields existed.

Confirmed to predate the current main: the suite already fails at 59daf8d (#307), before
#306 merged. The production code is correct; only the test doubles were stale. Nothing runs this
suite in CI, which is why it went unnoticed.

Solution

  • FakeGFALFileInterface now calls the real __init__ with only the grid-proxy lookup
    stubbed out, rather than mirroring the attributes it sets. That is what makes the fake track
    GFALFileInterface from now on: hand-mirroring is precisely what broke when listing_sizes
    appeared, and it broke silently until something read it.
  • Entry carries the fields of RunKit.grid_tools.FileInfo that law_gfal actually reads —
    name, size, is_dir — with defaults so the existing cases stay readable.
  • The fake tree may now map a directory to {name: size} as well as to a list of names, and an
    entry that is itself a key of the tree is reported as a directory, as a real listing would.

Also: the listing sizes had no test

listdir_info is the reason the fakes broke and had no coverage of its own. Three tests added:

  • sizes come from the listing and directories are excluded;
  • asking for sizes after an exists() that already listed the directory costs no second
    gfal-ls
    — the actual claim in its docstring;
  • a failed listing yields {} rather than raising.

Testing

  • test/test_path_cache.py: 13 passed (was 1 passed / 9 failed).
  • Whole test/ directory with ANALYSIS_PATH set: 79 passed.
  • The new tests were checked by mutation, so they are not vacuous:
    • dropping the not entry.is_dir filter in _cache_listing_sizes → the exclusion test fails;
    • dropping the _cache_listing_sizes call in listdir → the reuse test fails.
      law_gfal.py was restored unmodified afterwards.

No docs change: internal only — test doubles and test coverage, no user-visible behaviour.

@kandrosov
kandrosov merged commit 29ad83a into cms-flaf:main Aug 27, 2026
5 checks passed
@kandrosov
kandrosov deleted the fix-path-cache-test-fakes branch August 27, 2026 20:42
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