Skip to content

Reorganize tests - #89

Merged
teremterem merged 75 commits into
mainfrom
reorganize-tests
Mar 30, 2026
Merged

teremterem merged 75 commits into
mainfrom
reorganize-tests

Conversation

@teremterem

@teremterem teremterem commented Mar 26, 2026 •

Copy link
Copy Markdown
Owner

Open with Devin

Summary by CodeRabbit

  • Tests
    • Reorganized and expanded test coverage for decorators, context management, and promise resolution with improved naming conventions and comprehensive scenarios.
    • Enhanced test infrastructure with explicit timeout handling for threaded execution.
    • Consolidated related test suites for better maintainability.

@coderabbitai

coderabbitai Bot commented Mar 26, 2026 •

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

This pull request reorganizes and expands the test suite, primarily consolidating async and sync test coverage. It renames test functions for consistency, adds new test modules for synchronous context and function decorators, removes redundant test modules, and updates test utilities to support timeout constraints.

Changes

Cohort / File(s) Summary
Configuration Tests
tests/configuration/test_call_overrides_*.py
Renamed test_call_overrides_all_three to test_call_time_config_overrides in async variant; renamed sync tests to use generic names (test_call_time_config_overrides, test_config_kwargs_do_not_leak_into_function); added TODO comments about parameter list sync.
Context Decorator Tests
tests/decoration/test_context_decorator_*.py
Added comprehensive sync tests (test_context_decorator_sync.py); added comprehensive async tests (test_context_decorator_async.py). Both validate context activation/deactivation, argument forwarding, exception propagation, decorator invocation forms, and explicit parent behavior.
Method Context Decorator Tests
tests/decoration/test_method_context_decorator_*.py
Added new sync method context tests (test_method_context_decorator_sync.py); async variant simplified by removing standalone function tests and focusing on method-specific behavior; instance/static/class method decorators and exception handling covered.
Function Decorator Tests
tests/decoration/test_function_decorator_*.py
Async variant refactored with renamed tests (test_coroutine_executes_once → test_executes_once), modified call/signature assertions, added empty-parens decorator tests; sync variant similarly reorganized with promise object identity checks and thread execution verification.
Method Function Decorator Tests
tests/decoration/test_method_function_decorator_*.py
Async variant relocated/reworked empty-parens decorator tests with Promise object validation; renamed test_class_method_receives_cls_via_class → test_class_method_receives_cls; sync variant expanded with class-vs-instance access tests and decorator-ordering coverage.
Hierarchy/Nesting Tests
tests/hierarchy/test_nesting_*.py
Added new async nesting tests validating parent-chain resolution across call/await placement; sync variant renames tests for consistency (test_sync_promise_* → test_promising_function_*); new test test_promising_context_called_outside added.
Removed Test Modules
tests/promising_context/sync/test_sync_context_decorator.py, tests/promising_context/test_nested_contexts*.py
Entire modules deleted; coverage relocated to new consolidated test files (test_context_decorator_sync.py, test_nesting_sync.py, test_hierarchy/test_parent_resolution_sync.py).
Resolution Tests
tests/resolution/test_*_*.py
Systematic renaming for clarity: *_await_unpacks_all → *_unpack_all, *_unpack_once_* → *_unpack_once_*; renamed async tests to drop sync suffixes; removed test_from_concurrent_tasks, replaced test_parallel_await with test_concurrent_consumers with timeout; renamed helper _promise_expected_incomplete → _promise_not_expected_to_be_done.
Parent Resolution Tests
tests/hierarchy/test_parent_resolution_*.py
Added two new test modules validating Promise parent/active-context resolution for async and sync scenarios; covers top-level promises, active-promise access, and parent-child relationships.
Observability Tests
tests/observability/test_namespaces.py, tests/observability/test_traces.py
Updated expected namespace/qualname assertions to include full module path prefix (tests.observability.*::); updated trace output representations to reflect module-qualified names.
Test Utilities
tests/utils_for_tests.py
Updated run_in_thread signature to accept explicit timeout: float | None parameter and callable type annotation; daemon threads enabled; thread join enforces timeout with assertion.
Hierarchy Context Manager
tests/hierarchy/test_context_manager.py
Added explicit timeout=2 argument to run_in_thread call.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related issues

  • Verify AI-applied test renames #91: Directly addresses test renames specified in the issue (e.g., test_call_time_config_overrides_work_with_sync_functions → test_call_time_config_overrides) across both sync and async test files.
  • Review tests without sync/async counterparts #92: Addresses the request to review and add missing sync/async counterpart tests by adding comprehensive sync variants (test_context_decorator_sync.py, test_method_context_decorator_sync.py) and creating parity in decorator test coverage.

Possibly related PRs

  • PromisingContext (as a decorator AND a context manager) #57: This PR's new context decorator tests and parent-context/promise resolution tests directly target the PromisingContext and context-related APIs introduced in that PR.
  • Synchronous promising functions #54: This PR's addition of synchronous test coverage (test_context_decorator_sync.py, sync parent resolution tests) and run_in_thread timeout changes directly support the synchronous promising-function implementation from that PR.
  • Decorate methods, not classes #51: This PR's reorganized method decorator tests and assertions validate PromisingFunction descriptor/binding behavior for methods that was refined in that PR.

Poem

🐰 Tests dance in pairs, sync and async in air,
Reorganized, renamed, refactored with care!
New decorators shine, context flows so fine,
Promise chains align, parent links intertwine—
A warren of tests, all balanced and blessed! 🌟

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 63.41% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Reorganize tests' clearly and accurately summarizes the main change: a comprehensive reorganization of the test suite across multiple test files with renames, restructuring, and file movements.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch reorganize-tests

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 and usage tips.

devin-ai-integration[bot]

This comment was marked as resolved.

@teremterem
teremterem marked this pull request as ready for review March 30, 2026 08:54
coderabbitai[bot]

This comment was marked as resolved.

coderabbitai[bot]

This comment was marked as resolved.

devin-ai-integration[bot]

This comment was marked as resolved.

devin-ai-integration[bot]

This comment was marked as resolved.

@coderabbitai coderabbitai Bot 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.

♻️ Duplicate comments (4)
tests/decoration/test_method_function_decorator_async.py (1)

406-408: 🧹 Nitpick | 🔵 Trivial

Remove these PR-thread TODOs from the test body.

These comments leave the assertion strategy undecided and couple the suite to this PR discussion. Either keep these Promise-type checks as-is or move follow-up to an issue, but please drop the inline TODOs.

🧹 Suggested cleanup
     assert isinstance(MathUtils.triple, promising.PromisingFunction)

-    # TODO Apply these elaborate checks to other tests as well, or get rid of
-    #  them ?
-    #  https://github.com/teremterem/Promising/pull/89#discussion_r3008493442
     class_result = MathUtils.triple(5)
     instance_result = MathUtils().triple(5)
     assert isinstance(class_result, promising.Promise)
     assert isinstance(instance_result, promising.Promise)
     assert await class_result == 15
@@
     assert isinstance(Factory.create_name.__func__, promising.PromisingFunction)

-    # TODO Apply these elaborate checks to other tests as well, or get rid of
-    #  them ?
-    #  https://github.com/teremterem/Promising/pull/89#discussion_r3008493442
     class_result = Factory.create_name()
     instance_result = Factory().create_name()
     assert isinstance(class_result, promising.Promise)
     assert isinstance(instance_result, promising.Promise)
     assert await class_result == "Factory"

Also applies to: 431-433

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tests/decoration/test_method_function_decorator_async.py` around lines 406 -
408, Remove the inline PR-thread TODO comments from the test body in
tests/decoration/test_method_function_decorator_async.py (the comment block
starting with "# TODO Apply these elaborate checks..." around the region that
also has a duplicate at lines ~431-433); either keep the current Promise-type
checks as-is or open a separate issue for follow-up, but delete these inline
TODO comment lines so the test suite is not coupled to the PR discussion.
tests/decoration/test_method_context_decorator_sync.py (2)

79-81: 🧹 Nitpick | 🔵 Trivial

Remove the PR-thread TODO from the committed test.

This leaves the assertion strategy undecided and ties the suite to a review discussion. Keep the assertion if you want the coverage, but drop the inline TODO block.

🧹 Suggested cleanup
     # Verify context is properly deactivated after exception
-    # TODO Apply this check to other tests as well ? Make it more elaborate ?
-    #  Get rid of it ?
-    #  https://github.com/teremterem/Promising/pull/89#discussion_r3008493421
     assert promising.get_active_context(raise_if_none=False) is None
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tests/decoration/test_method_context_decorator_sync.py` around lines 79 - 81,
Remove the inline PR-thread TODO comment block (the three commented lines
starting with "# TODO Apply this check..." through the GitHub PR link) from the
committed test file so the test suite no longer contains review discussion;
retain the actual assertion(s) in the test if coverage is desired, but delete
the TODO lines and any duplicate comment to keep the test file clean.

6-6: 🧹 Nitpick | 🔵 Trivial

Use regular def for these sync-only tests.

Every test in this module is declared async def, but the bodies are fully synchronous. That adds unnecessary async-test/plugin coupling to a file whose purpose is to exercise sync decorators.

Run this to confirm there is no async-only syntax in the module before converting them mechanically:

#!/bin/bash
python - <<'PY'
import ast
from pathlib import Path

path = Path("tests/decoration/test_method_context_decorator_sync.py")
tree = ast.parse(path.read_text())

for node in tree.body:
    if isinstance(node, ast.AsyncFunctionDef):
        has_async_syntax = any(
            isinstance(n, (ast.Await, ast.AsyncFor, ast.AsyncWith))
            for n in ast.walk(node)
        )
        print(f"Line {node.lineno}: {node.name} -> async-only-syntax={has_async_syntax}")
PY

If every row prints async-only-syntax=False, these can be switched to regular def tests without changing the test bodies.

Also applies to: 21-21, 45-45, 64-64, 85-85, 94-94, 111-111, 130-130, 147-147, 167-167, 185-185, 204-204, 220-220, 237-237, 255-255, 265-265

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tests/decoration/test_method_context_decorator_sync.py` at line 6, Convert
sync-only test coroutines in this module from "async def" to regular "def": for
each AsyncFunctionDef such as test_instance_method_activates_context, change its
signature from "async def ..." to "def ..." (and do the same for the other async
tests in this file) after first running the provided AST-check script to ensure
no async-only syntax (Await/AsyncFor/AsyncWith) is present; this keeps test
bodies unchanged and removes unnecessary async-test/plugin coupling while
preserving existing function names and behavior.
tests/decoration/test_method_context_decorator_async.py (1)

79-81: 🧹 Nitpick | 🔵 Trivial

Remove the PR-thread TODO from the committed test.

This leaves the assertion strategy undecided and couples the suite to a review discussion. Keep the assertion or track follow-up elsewhere, but please drop the inline TODO block.

🧹 Suggested cleanup
     # Verify context is properly deactivated after exception
-    # TODO Apply this check to other tests as well ? Make it more elaborate ?
-    #  Get rid of it ?
-    #  https://github.com/teremterem/Promising/pull/89#discussion_r3008493421
     assert promising.get_active_context(raise_if_none=False) is None
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tests/decoration/test_method_context_decorator_async.py` around lines 79 -
81, Remove the PR-thread TODO comment block in
tests/decoration/test_method_context_decorator_async.py (the three-line TODO
starting with "# TODO Apply this check to other tests as well ?") so the
committed test no longer references a review discussion; either delete those
lines entirely or replace them with a short, concrete comment or an issue/PR
reference if you want to track follow-up (no inline discussion notes).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Duplicate comments:
In `@tests/decoration/test_method_context_decorator_async.py`:
- Around line 79-81: Remove the PR-thread TODO comment block in
tests/decoration/test_method_context_decorator_async.py (the three-line TODO
starting with "# TODO Apply this check to other tests as well ?") so the
committed test no longer references a review discussion; either delete those
lines entirely or replace them with a short, concrete comment or an issue/PR
reference if you want to track follow-up (no inline discussion notes).

In `@tests/decoration/test_method_context_decorator_sync.py`:
- Around line 79-81: Remove the inline PR-thread TODO comment block (the three
commented lines starting with "# TODO Apply this check..." through the GitHub PR
link) from the committed test file so the test suite no longer contains review
discussion; retain the actual assertion(s) in the test if coverage is desired,
but delete the TODO lines and any duplicate comment to keep the test file clean.
- Line 6: Convert sync-only test coroutines in this module from "async def" to
regular "def": for each AsyncFunctionDef such as
test_instance_method_activates_context, change its signature from "async def
..." to "def ..." (and do the same for the other async tests in this file) after
first running the provided AST-check script to ensure no async-only syntax
(Await/AsyncFor/AsyncWith) is present; this keeps test bodies unchanged and
removes unnecessary async-test/plugin coupling while preserving existing
function names and behavior.

In `@tests/decoration/test_method_function_decorator_async.py`:
- Around line 406-408: Remove the inline PR-thread TODO comments from the test
body in tests/decoration/test_method_function_decorator_async.py (the comment
block starting with "# TODO Apply these elaborate checks..." around the region
that also has a duplicate at lines ~431-433); either keep the current
Promise-type checks as-is or open a separate issue for follow-up, but delete
these inline TODO comment lines so the test suite is not coupled to the PR
discussion.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 12bb729a-7750-49f9-add6-85e0a93424d4

📥 Commits

Reviewing files that changed from the base of the PR and between 72624bf and e281ed1.

📒 Files selected for processing (13)
  • tests/decoration/test_function_decorator_async.py
  • tests/decoration/test_function_decorator_sync.py
  • tests/decoration/test_method_context_decorator_async.py
  • tests/decoration/test_method_context_decorator_sync.py
  • tests/decoration/test_method_function_decorator_async.py
  • tests/decoration/test_method_function_decorator_sync.py
  • tests/hierarchy/test_context_manager.py
  • tests/hierarchy/test_parent_resolution_async.py
  • tests/hierarchy/test_parent_resolution_sync.py
  • tests/resolution/test_promise_as_future_async.py
  • tests/resolution/test_promise_as_future_sync.py
  • tests/resolution/test_promising_function_run.py
  • tests/utils_for_tests.py

@teremterem
teremterem merged commit 1902591 into main Mar 30, 2026
3 checks passed
@teremterem
teremterem deleted the reorganize-tests branch March 30, 2026 18:01
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