8000 test(di): add comprehensive test suite for Container and ServiceLocator by dominicusin · Pull Request #64 · dominicusin/package-maximizer · GitHub
[go: up one dir, main page]

Skip to content

test(di): add comprehensive test suite for Container and ServiceLocator - #64

Merged
dominicusin merged 1 commit into
mainfrom
test/di-container-coverage
Sep 1, 2026
Merged

dominicusin merged 1 commit into
mainfrom
test/di-container-coverage

Conversation

@dominicusin
Copy link
Copy Markdown
Owner

Summary

  • Added 23 tests for DI container
  • Coverage: di/container 73% → 89%
  • Tests: 555 → 578 passed, total 87% coverage

Test plan

  • 578 passed, 2 skipped
  • Coverage 87%
  • CI green (pending)

- Added 23 tests for DI container
- Coverage: di/container 73% → 89%
- Tests: 555 → 578 passed, total 87% coverage
@coderabbitai
coderabbitai Bot commented Sep 1, 2026
Copy link
Copy Markdown

Warning

Review limit reached

Next included review available in 50 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Team

Run ID: 3251ae95-3f80-45bd-8dd2-94125ef009e8

📥 Commits

Reviewing files that changed from the base of the PR and between b3a04d5 and 554d4f2.

📒 Files selected for processing (1)
  • tests/test_di_container.py

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@qodo-code-review
Copy link
Copy Markdown

PR Summary by Qodo

Expand DI container and service locator test coverage

🧪 Tests 🕐 10-20 Minutes

Grey Divider

AI Description

• Adds 23 tests for registration, lifecycles, constructor resolution, and service retrieval.
• Verifies ServiceLocator lifecycle and inject decorator metadata behavior.
• Raises DI container coverage from 73% to 89%.
Diagram

graph TD
  T["DI Test Suite"] --> C["Container"] --> R["Service Registries"]
  C --> D["Constructor Resolution"]
  T --> S["Service Locator"] --> C
  T --> I["Inject Decorator"]
Loading
High-Level Assessment

The focused pytest suite is appropriate for this isolated coverage expansion. Parameterizing similar cases was considered, but explicit tests better preserve the distinct registration, resolution, and failure contracts under review.

Files changed (1) +235 / -0

Tests (1) +235 / -0
test_di_container.pyAdd comprehensive DI container unit tests +235/-0

Add comprehensive DI container unit tests

• Adds 23 tests covering empty initialization, singleton and transient registration, instance and factory registration, constructor dependency resolution, lazy singleton creation, auto-resolution, and aliases. Also verifies ServiceLocator creation, reuse, reset, and resolution behavior plus inject decorator metadata and stacking semantics.

tests/test_di_container.py

@qodo-code-review
Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (1) 📘 Rule violations (0) 📜 Skill insights (0)

Grey Divider


Action required

1. ServiceLocator test drops decorator 🐞 Bug ≡ Correctness
Description
test_register calls ServiceLocator.container().register("singleton")(TestService), but
register("singleton") only returns a decorator and the test does not invoke that decorator with
TestService. Consequently TestService is absent from _singletons, causing the newly added test
suite to fail.
Code

tests/test_di_container.py[R198-199]

+        ServiceLocator.container().register("singleton")(TestService)
+        assert TestService in ServiceLocator.container()._singletons
Evidence
The implementation separates decorator creation from registration: register returns decorator,
and only the inner function inserts the class into _singletons. The added test's call does not
execute that inner function with TestService, so its subsequent membership assertion is false.

package_maximizer/di/container.py[32-44]
tests/test_di_container.py[197-199]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The test invokes `Container.register("singleton")` but discards its returned decorator, so `TestService` is never registered and the assertion fails.

## Issue Context
`Container.register` returns `decorator`; registration occurs only when that decorator is called with the class. `ServiceLocator.register` also discards the decorator, so using the container directly still requires applying the returned decorator.

## Fix Focus Areas
- tests/test_di_container.py[198-199]

Change the test to apply the decorator, for example `ServiceLocator.container().register("singleton")(TestService)` is currently syntactically present but must be verified against the implementation; alternatively use an explicit decorator variable and call it with `TestService`, or use `register_instance`. Ensure the final assertion observes `TestService` in the singleton registry.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

Context sources
Review mode: 🚀 Fast: This is a localized, single-file addition of tests for one DI module, with no production behavior or high-risk path changes; a light review should suffice.

Grey Divider

Tip of the day
💡 Did you know, you can describe a rule in plain language on the Rules page and Qodo drafts it for you

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Qodo Logo

Comment on lines +198 to +199
ServiceLocator.container().register("singleton")(TestService)
assert TestService in ServiceLocator.container()._singletons
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Action required

1. Servicelocator test drops decorator 🐞 Bug ≡ Correctness

test_register calls ServiceLocator.container().register("singleton")(TestService), but
register("singleton") only returns a decorator and the test does not invoke that decorator with
TestService. Consequently TestService is absent from _singletons, causing the newly added test
suite to fail.
Agent Prompt
## Issue description
The test invokes `Container.register("singleton")` but discards its returned decorator, so `TestService` is never registered and the assertion fails.

## Issue Context
`Container.register` returns `decorator`; registration occurs only when that decorator is called with the class. `ServiceLocator.register` also discards the decorator, so using the container directly still requires applying the returned decorator.

## Fix Focus Areas
- tests/test_di_container.py[198-199]

Change the test to apply the decorator, for example `ServiceLocator.container().register("singleton")(TestService)` is currently syntactically present but must be verified against the implementation; alternatively use an explicit decorator variable and call it with `TestService`, or use `register_instance`. Ensure the final assertion observes `TestService` in the singleton registry.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

@dominicusin
dominicusin merged commit 975feb6 into main Sep 1, 2026
16 of 17 checks passed
@dominicusin
dominicusin deleted the test/di-container-coverage branch September 1, 2026 02:33
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

0