Skip to content

Add tests for package_search (#2092)#2149

Open
ahlbertng wants to merge 4 commits into
AcademySoftwareFoundation:mainfrom
ahlbertng:add-package-search-tests
Open

Add tests for package_search (#2092)#2149
ahlbertng wants to merge 4 commits into
AcademySoftwareFoundation:mainfrom
ahlbertng:add-package-search-tests

Conversation

@ahlbertng

@ahlbertng ahlbertng commented Jul 8, 2026

Copy link
Copy Markdown

Description

This PR adds unit tests for src/rez/package_search.py, which currently has no test coverage (as noted in #2092).

Addresses part of #2092.

What's tested

get_reverse_dependency_tree()
Correctly builds a reverse dependency tree for a package with known direct dependents
Respects the depth argument (e.g. depth=0 returns only the root package)
ResourceSearcher.search()
Finds all versions of a package family
Returns only the latest version when latest=True
ResourceSearchResultFormatter
Default (no output_format) output correctly shows a package's qualified name
ResourceSearchResult
Correctly stores resource, resource_type, and validation_error (including default None)

Notes

Tests reuse the existing solver/packages test data already used by test_packages.py, so no new test fixtures were added.
get_plugins() is not yet covered, no existing test data currently includes packages with plugin_for set. Open to guidance on whether to add new fixture packages for this, or if there's a preferred approach.

@ahlbertng
ahlbertng requested a review from a team as a code owner July 8, 2026 02:04
@linux-foundation-easycla

linux-foundation-easycla Bot commented Jul 8, 2026

Copy link
Copy Markdown

CLA Signed
The committers listed above are authorized under a signed CLA.

ahlbertng added 2 commits July 8, 2026 03:22
Signed-off-by: Ahlbertng <70105688+ahlbertng@users.noreply.github.com>
Signed-off-by: Ahlbertng <70105688+ahlbertng@users.noreply.github.com>
@ahlbertng
ahlbertng force-pushed the add-package-search-tests branch from c11bd7b to 26ef581 Compare July 8, 2026 02:22
ahlbertng added 2 commits July 8, 2026 03:56
Signed-off-by: Ahlbertng <70105688+ahlbertng@users.noreply.github.com>
Signed-off-by: Ahlbertng <70105688+ahlbertng@users.noreply.github.com>
@codecov

codecov Bot commented Jul 17, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 61.72%. Comparing base (1a83acf) to head (65d0f8d).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2149      +/-   ##
==========================================
+ Coverage   61.31%   61.72%   +0.41%     
==========================================
  Files         164      164              
  Lines       20568    20568              
  Branches     3575     3575              
==========================================
+ Hits        12611    12696      +85     
+ Misses       7085     6983     -102     
- Partials      872      889      +17     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@maxnbk maxnbk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the submission of this new set of tests. We really appreciate any added coverage we can squeeze into the repo at this point, especially for such un-tested areas.

I've issued some specific comments attached to areas near the code that they pertain to. These are the main comments I'm making that would flip my recommendation from "don't merge" to "do merge". I made some specific line comments, but the real issue is that the current flake8 linter job fails, so just address those items.

I would express that the largest useful gaps to continue covering, whether they are a part of this PR, or you or anyone else tackles with additional work, would be these:

(Please comment, if you intend to go further with the coverage and aim to address these as well, or if you want to keep this PR self-contained just to the current change-set)


test the validate=True path. The ResourceSearcher.search() method has a substantial validate code path with error handling for ResourceContentError. No tests exercise this yet, and is arguably the most complex portion of the module.

test for glob patterns. ResourceSearcher.search() uses fnmatch.fnmatch on the name pattern. A test like searcher.search("py*") would verify the glob codepaths, which is a core feature of the searcher.

test for family resource type. When no version range is specified and multiple families match, the searcher returns resource_type="family". The current tests only exercise the package resource type.

self.assertEqual(resource_type, "package")
self.assertEqual(len(results), 1)
self.assertEqual(results[0].resource.version, Version("3"))
def test_formatter_default_output(self) -> None:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could use a newline between this test-def and the prior line, this will likely fail future-enforced linter rules (E305)

self.assertEqual(len(formatted_lines), 1)
text, color = formatted_lines[0]
self.assertEqual(text, "pydad-3")
def test_resource_search_result(self) -> None:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(same, could use a newline between this and the line above)

def tearDownClass(cls) -> None:
TempdirMixin.tearDownClass()

def test_reverse_dependency_tree(self) -> None:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

get_reverse_dependency_tree tests don't verify the graph (g). The function returns a 2-tuple (pkgs_list, g) where g is a digraph. The tests unpack both but only assert on pkgs_list. The graph is arguably the more valuable output - it encodes the edge relationships. A test verifying g.nodes() and g.edges() would be more meaningful than just checking the list-of-lists.

pkgs_list, g = get_reverse_dependency_tree("pymum")

self.assertEqual(pkgs_list[0], ["pymum"])
self.assertEqual(pkgs_list[1], ["pydad", "pyson"])

@maxnbk maxnbk Jul 17, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The assertion pkgs_list[1] == ["pydad", "pyson"] depends on the sorted order of the working set in package_search.py (sorted(list(working_set_))). That's correct today, but the test doesn't communicate why those two packages appear - it's because pymum-3 is required by pydad-3 and pyson-2, and the function only looks at the latest version of each family. If someone adds a new package that requires pymum to the fixture, or changes which version is latest, the assertion breaks with no obvious connection to the underlying logic. A set-based assertion (self.assertEqual(set(pkgs_list[1]), {"pydad", "pyson"})) would be both more robust and more honest about what the test is actually verifying - that the direct dependents are found - without coupling to sort order.

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.

2 participants