added the missing tests (and verified they pass)#6170
added the missing tests (and verified they pass)#6170masenf merged 4 commits intoreflex-dev:mainfrom
Conversation
Greptile SummaryThis PR replaces two no-op test stubs with real implementations: one for
Confidence Score: 5/5Safe to merge — both changed files are test-only additions with no production code impact. The changes add real test coverage where stubs existed before. The route-path comparison and the redundant asyncio marker are minor nits that won't cause CI failures under default configuration, and no production logic is touched. No files require special attention; both changed files are test-only. Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[compile_state called] --> B{Running event loop?}
B -- No --> C[asyncio.run _resolve_delta]
B -- Yes --> D[ThreadPoolExecutor]
D --> E[asyncio.run in thread]
C --> F[Return sorted state dict]
E --> F
G[test without loop] --> A
H[test with loop] --> A
Reviews (2): Last reviewed commit: "Apply suggestion from @greptile-apps[bot..." | Re-trigger Greptile |
| ) | ||
| Upload.is_used = False |
There was a problem hiding this comment.
Fragile cleanup – Upload.is_used not reset on test failure
Upload.is_used = False is placed after the with chdir(tmp_path): block without a try/finally guard. If either assert any(...) call on lines 1688–1696 raises an AssertionError, the cleanup line never executes and Upload.is_used is left as True for subsequent tests. Wrap the assertions in try/finally or, preferably, use the existing monkeypatch fixture for test-scoped teardown:
| ) | |
| Upload.is_used = False | |
| finally: | |
| Upload.is_used = False |
Or, restructure the test to use the monkeypatch fixture:
def test_app_with_optional_endpoints(tmp_path: Path, monkeypatch):
from reflex.components.core.upload import Upload
from starlette.routing import Mount, Route
monkeypatch.setattr(Upload, "is_used", False)
with chdir(tmp_path):
app = App()
monkeypatch.setattr(Upload, "is_used", True)
app._add_optional_endpoints()
...Using monkeypatch guarantees restoration to the original value regardless of how the test exits.
There was a problem hiding this comment.
i suggest setting Upload.is_used with monkeypatch inside a fixture that this test depends on, that way the clean up and test logic are cleanly separated
There was a problem hiding this comment.
Good call – that's cleaner. Here's how it would look:
| ) | |
| Upload.is_used = False | |
| @pytest.fixture | |
| def upload_component(monkeypatch): | |
| from reflex.components.core.upload import Upload | |
| monkeypatch.setattr(Upload, "is_used", False) | |
| yield Upload | |
| def test_app_with_optional_endpoints(tmp_path: Path, upload_component): | |
| from starlette.routing import Mount, Route | |
| with chdir(tmp_path): | |
| app = App() | |
| upload_component.is_used = True | |
| app._add_optional_endpoints() | |
| assert app._api is not None | |
| upload_path = str(constants.Endpoint.UPLOAD) | |
| routes = list(app._api.routes) | |
| assert any( | |
| isinstance(r, Route) | |
| and r.path == upload_path | |
| and "POST" in getattr(r, "methods", set()) | |
| for r in routes | |
| ) | |
| assert any( | |
| isinstance(r, Mount) and r.path == upload_path and r.name == "uploaded_files" | |
| for r in routes | |
| ) |
The fixture ensures Upload.is_used is False initially and handles cleanup automatically, while the test logic stays focused on the actual behavior being tested.
There was a problem hiding this comment.
Actually, I can't provide this as an inline suggestion because:
- The fixture needs to be placed before the test function
- The comment is only on lines 1697-1698 (the function signature)
- Inline suggestions only modify the exact lines the comment is attached to
Here's the pattern you should use:
@pytest.fixture
def upload_enabled(monkeypatch):
"""Fixture that enables Upload and cleans up afterward."""
from reflex.components.core.upload import Upload
monkeypatch.setattr(Upload, "is_used", True)
yield
monkeypatch.setattr(Upload, "is_used", False)
def test_app_with_optional_endpoints(tmp_path: Path, upload_enabled):
from reflex.components.core.upload import Upload
from starlette.routing import Mount, Route
with chdir(tmp_path):
app = App()
app._add_optional_endpoints()
assert app._api is not None
upload_path = str(constants.Endpoint.UPLOAD)
routes = list(app._api.routes)
assert any(
isinstance(r, Route)
and r.path == upload_path
and "POST" in getattr(r, "methods", set())
for r in routes
)
assert any(
isinstance(r, Mount) and r.path == upload_path and r.name == "uploaded_files"
for r in routes
)Place the upload_enabled fixture above the test function. The fixture handles both setup and teardown automatically, keeping the test logic clean.
masenf
left a comment
There was a problem hiding this comment.
thanks for adding the test cases
| ) | ||
| Upload.is_used = False |
There was a problem hiding this comment.
i suggest setting Upload.is_used with monkeypatch inside a fixture that this test depends on, that way the clean up and test logic are cleanly separated
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
|
@greptile-apps re-review |
Merging this PR will not alter performance
Comparing Footnotes
|
All Submissions:
Type of change
Please delete options that are not relevant.
New Feature Submission:
Changes To Core Features:
After these steps, you're ready to open a pull request.