Skip to content

Add tests for get_scope with builtin types, classes, and methods#189

Merged
samwaseda merged 5 commits intosamwaseda-patch-1from
copilot/sub-pr-186
Mar 18, 2026
Merged

Add tests for get_scope with builtin types, classes, and methods#189
samwaseda merged 5 commits intosamwaseda-patch-1from
copilot/sub-pr-186

Conversation

Copy link
Contributor

Copilot AI commented Mar 18, 2026

Summary

get_scope was broadened to accept Callable[..., Any] | type[Any] but lacked tests exercising the new callable categories. Adds coverage for actual "rubber meets the road" usage with builtins, user-defined classes, static methods, and lambdas.

Related Issue(s)

Extends the fix in #186.

Backward Compatibility

No behavioral changes — test-only additions.

Implementation Notes

New test cases in TestGetScope:

Test What it exercises
test_builtin_type get_scope(int) — hits sys.modules fallback since inspect.getmodule(int) returns None
test_builtin_function get_scope(len) — same fallback path
test_user_defined_class get_scope(Outer) — direct inspect.getmodule path, verifies module globals visible
test_static_method get_scope(Outer.Inner.nested_func) — nested staticmethod traversal
test_lambda module-level identity lambda — primary assertion verifies scope.identity is identity, consistent with the pattern used by all other tests
scope = get_scope(int)       # builtin type — uses sys.modules fallback
assert scope.int is int
assert scope.len is len

scope = get_scope(MyClass)   # user-defined class
assert scope.MyClass is MyClass

scope = get_scope(MyClass.static_method)  # static method
assert scope.MyClass is MyClass

scope = get_scope(identity)  # module-level lambda
assert scope.identity is identity

flowrep/_version.py (a generated build artifact) is excluded from the repository via .gitignore to prevent it from being accidentally committed.


💬 Send tasks to Copilot coding agent from Slack and Teams to turn conversations into code. Copilot posts an update in your thread when it's finished.

Copilot AI and others added 2 commits March 18, 2026 15:53
…ypes

Co-authored-by: samwaseda <37879103+samwaseda@users.noreply.github.com>
Co-authored-by: samwaseda <37879103+samwaseda@users.noreply.github.com>
@samwaseda
Copy link
Member

@copilot Remove _version.py

@samwaseda samwaseda marked this pull request as ready for review March 18, 2026 15:54
Copilot AI changed the title [WIP] Change get_scope parameter type from FunctionType to object Add tests for get_scope with builtin types, classes, and methods Mar 18, 2026
Copilot AI requested a review from samwaseda March 18, 2026 15:55
Copy link
Contributor Author

Copilot AI commented Mar 18, 2026

@copilot Remove _version.py

_version.py was already removed from git tracking and added to .gitignore in commit 1514891. The file is no longer part of the repository.

@codecov
Copy link

codecov bot commented Mar 18, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.97%. Comparing base (092f66c) to head (f9e61bf).
⚠️ Report is 6 commits behind head on samwaseda-patch-1.

Additional details and impacted files
@@                Coverage Diff                 @@
##           samwaseda-patch-1     #189   +/-   ##
==================================================
  Coverage              97.97%   97.97%           
==================================================
  Files                     34       34           
  Lines                   2268     2268           
==================================================
  Hits                    2222     2222           
  Misses                    46       46           

☔ View full report in Codecov by Sentry.
📢 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.

Comment on lines +118 to +121
fn = lambda x: x # noqa: E731
scope = object_scope.get_scope(fn)
self.assertIs(scope.add, add)
self.assertIs(scope.len, len)
Copy link
Member

Choose a reason for hiding this comment

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

Assertions are unrelated to the newly scoped object

Copy link
Member

Choose a reason for hiding this comment

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

@copilot Assertions are unrelated to the newly scoped object

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 5ec4ac0. Moved the lambda to module level as identity = lambda x: x, so the test now asserts scope.identity is identity — directly verifying the scoped object is present in its own scope, consistent with the pattern used in the other TestGetScope tests.

Copy link
Member

Choose a reason for hiding this comment

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

Works for me. I added a suggestion to remove the vestigial add check.

Co-authored-by: samwaseda <37879103+samwaseda@users.noreply.github.com>
Co-authored-by: Liam Huber <liamhuber@greyhavensolutions.com>
@samwaseda samwaseda merged commit 3c260aa into samwaseda-patch-1 Mar 18, 2026
3 checks passed
@samwaseda samwaseda deleted the copilot/sub-pr-186 branch March 18, 2026 18:02
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.

3 participants