Add test coverage for intern_atom and atom cache lifecycle#4
Add test coverage for intern_atom and atom cache lifecycle#4jholveck merged 4 commits intofeat-xcb-better-monitorsfrom
Conversation
Co-authored-by: jholveck <240807535+jholveck@users.noreply.github.com>
jholveck
left a comment
There was a problem hiding this comment.
It's ok, but that's a lot of code. Can we compress and combine these some? Some of the repeated code could also go into methods on a test class. BTW, there's a running X server (typically Xvfb) in the usual test environment, so we can talk to it if needed, but we don't have to.
Co-authored-by: jholveck <240807535+jholveck@users.noreply.github.com>
Refactored in 415fcde. The 9 standalone functions + helper are replaced by a |
src/tests/test_xcb.py
Outdated
| monkeypatch.setattr(xcb, "initialize", lambda: None) | ||
|
|
||
| assert cache_key not in xcb._ATOM_CACHE | ||
| xcb.connect() |
There was a problem hiding this comment.
Is there a point to mocking the connection? Can we just get the cache keys, create a new real connection, verify its address had been added to the cache keys, close the connection, and verify it was deleted?
There was a problem hiding this comment.
Done in 362c124. test_atom_cache_lifecycle now snapshots the existing cache keys, calls xcb.connect() to get a real connection, asserts the new key appeared with an empty dict, calls xcb.disconnect(), and asserts the key is gone and the cache is back to its original state.
src/tests/test_xcb.py
Outdated
| """Tests for xcb.intern_atom and the _ATOM_CACHE mechanism.""" | ||
|
|
||
| @pytest.fixture(autouse=True) | ||
| def setup_intern_atom(self, monkeypatch: pytest.MonkeyPatch) -> Generator[None, None, None]: |
There was a problem hiding this comment.
Most of our test code tests against a real X server; you can assume that a real X server (like Xvfb) is available in the CI/CD test environment. Is there anything that we're testing that requires a completely mocked connection? We might need to monkey-patch out xcb.LIB.xcb_intern_atom with a mock for test_cache_miss_calls_xcb_and_caches_result, if that can be done.
There was a problem hiding this comment.
Done in 362c124. The setup_intern_atom fixture now calls xcb.connect()/xcb.disconnect() for a real connection. Only LIB.xcb.xcb_intern_atom is selectively patched (via _mock_xcb_intern_atom) in the tests that need to spy on or control that call. test_only_if_exists_returns_none_when_missing and test_pointer_connection_uses_correct_cache_key talk directly to the real X server.
Co-authored-by: jholveck <240807535+jholveck@users.noreply.github.com>
🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.