Add failing tests for LookupIndex context manager protocol (#143) [ON HOLD]#144
Add failing tests for LookupIndex context manager protocol (#143) [ON HOLD]#144
Conversation
There was a problem hiding this comment.
Pull request overview
Adds new “test-first” coverage defining the expected contract for Issue #143 (LookupIndex context manager protocol and transform_spec resource cleanup), without changing production code.
Changes:
- Introduces tests asserting
LookupIndexsupportswithvia__enter__/__exit__and cleans up on exceptions. - Adds an integration-style test asserting
transform_speccloses theLookupIndexafter iteration completes. - Embeds minimal inline source/target schemas + TSV fixtures needed to exercise the cleanup path.
| """Tests for LookupIndex context manager protocol and resource cleanup. | ||
|
|
||
| These tests verify that LookupIndex supports ``with`` statement usage | ||
| and that transform_spec properly cleans up its LookupIndex. Currently, | ||
| LookupIndex does NOT implement __enter__/__exit__, so these tests are | ||
| expected to fail until the protocol is added. | ||
|
|
||
| See: https://github.com/linkml/linkml-map/issues/143 |
There was a problem hiding this comment.
These tests are intentionally failing (per docstring), which will break the main test suite if this PR is merged on its own. Consider marking them with pytest.mark.xfail (with a link/reason for #143) or skipping until the implementation PR lands, or alternatively include the implementation changes in the same PR so CI stays green.
| # After exiting the context, the connection should be closed | ||
| assert not idx.is_registered("data") | ||
|
|
There was a problem hiding this comment.
The docstring says the DuckDB connection should be closed after exiting the context, but the assertion only checks that the table is no longer registered (which could be satisfied without closing the connection). To make this test actually enforce resource cleanup, add an assertion that a DuckDB operation (e.g., register_table/lookup_row) fails after the with block, ideally by asserting on duckdb.Error (or similar).
| # Connection should still be cleaned up | ||
| assert not idx.is_registered("data") | ||
|
|
There was a problem hiding this comment.
Same as above: this only checks that _tables was cleared, not that the DuckDB connection was actually closed. To validate cleanup on exceptions, consider also asserting that a subsequent DuckDB operation on idx fails after the with exits (e.g., register_table/lookup_row raising duckdb.Error).
| # After transform_spec completes, the LookupIndex should be closed. | ||
| # Attempting to use it should fail. | ||
| with pytest.raises((duckdb.ConnectionException, duckdb.InvalidInputException)): | ||
| tr.lookup_index.register_table( | ||
| "should_fail", tmp_path / "sites.tsv", "site_code" | ||
| ) |
There was a problem hiding this comment.
This assertion is a bit brittle because it assumes (1) transform_spec leaves a non-None lookup_index instance attached to the transformer, and (2) DuckDB raises one of these two specific exception types when the connection is closed. A cleanup implementation that sets transformer.lookup_index = None, or a DuckDB version that raises a different subclass, would cause this test to fail despite correct cleanup. Consider accepting AttributeError/None and/or asserting on the broader duckdb.Error base class instead of specific subclasses.
Address review suggestions from Copilot on PR #144: - Context manager tests now also assert that DuckDB operations raise after the `with` block exits, not just that is_registered() returns False. This verifies the connection is actually closed, not just that the internal table dict was cleared. - transform_spec cleanup test now accepts EITHER implementation strategy: setting lookup_index to None OR calling close(). This avoids brittleness if the fix nulls the attribute instead of closing the connection. All 3 tests still fail as expected on the cross-table-lookup branch. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
Addressed Copilot's inline feedback in 716ef0b:
All 3 tests still fail as expected. |
Address review suggestions from Copilot on PR #144: - Context manager tests now also assert that DuckDB operations raise after the `with` block exits, not just that is_registered() returns False. This verifies the connection is actually closed, not just that the internal table dict was cleared. - transform_spec cleanup test now accepts EITHER implementation strategy: setting lookup_index to None OR calling close(). This avoids brittleness if the fix nulls the attribute instead of closing the connection. All 3 tests still fail as expected on the cross-table-lookup branch. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
0b74ba2 to
760a141
Compare
Address review suggestions from Copilot on PR #144: - Context manager tests now also assert that DuckDB operations raise after the `with` block exits, not just that is_registered() returns False. This verifies the connection is actually closed, not just that the internal table dict was cleared. - transform_spec cleanup test now accepts EITHER implementation strategy: setting lookup_index to None OR calling close(). This avoids brittleness if the fix nulls the attribute instead of closing the connection. All 3 tests still fail as expected on the cross-table-lookup branch. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
8e7ec33 to
6100bc1
Compare
f33a79e to
c718189
Compare
These 3 tests document the expected behavior described in #143: - LookupIndex should support `with` statement (context manager protocol) - LookupIndex should clean up on exception within context - transform_spec should close LookupIndex after iteration completes All 3 tests currently FAIL because LookupIndex lacks __enter__/__exit__ and transform_spec does not call close(). They will pass once #143 is implemented. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Address review suggestions from Copilot on PR #144: - Context manager tests now also assert that DuckDB operations raise after the `with` block exits, not just that is_registered() returns False. This verifies the connection is actually closed, not just that the internal table dict was cleared. - transform_spec cleanup test now accepts EITHER implementation strategy: setting lookup_index to None OR calling close(). This avoids brittleness if the fix nulls the attribute instead of closing the connection. All 3 tests still fail as expected on the cross-table-lookup branch. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…spec LookupIndex now supports `with` statement usage via __enter__/__exit__. transform_spec() closes the LookupIndex it creates after iteration completes, preventing DuckDB connection leaks. Closes #143 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
c718189 to
75a6a93
Compare
|
@turbomam I think I was able to fix this on main and now we should be able to merge this. Does this cover what you intended to cover still? |
amc-corey-cox
left a comment
There was a problem hiding this comment.
This looks good to me.
Status: ON HOLD — waiting for #143 implementation
These tests define the expected contract for #143. They will fail CI until the implementation lands. This PR should be merged after #143 is implemented, or the implementation can be done directly in this branch.
Summary
Adds 3 tests that currently fail — they describe the expected behavior for #143 (LookupIndex context manager + resource cleanup in
transform_spec).What fails and why
test_context_manager_basicAttributeError: __enter__LookupIndexhas no__enter__/__exit__test_context_manager_cleans_up_on_exceptionAttributeError: __enter__test_transform_spec_closes_lookup_indexDID NOT RAISEtransform_specnever callsclose()— the DuckDB connection is still usable after iterationProposed fix (for #143)
Two small changes:
__enter__/__exit__toLookupIndextransform_specafter the outer loopHappy to implement this if you'd like, or feel free to take it — the fix is mechanical.
Related