Skip to content

Commit 7ac0f21

Browse files
authored
refactor(test): Split test helpers into focused modules (#578)
This refactors the test helper functionality into separate modules and removes unused path constants: Breaking changes: - Split libtmux.test into focused modules: - libtmux.test.constants: Test-related constants (TEST_SESSION_PREFIX, etc.) - libtmux.test.environment: Environment variable mocking - libtmux.test.random: Random string generation utilities - libtmux.test.temporary: Temporary session/window management - Import paths have changed, requiring updates in downstream code - Removed unused path constants: - current_dir - example_dir - fixtures_dir Other changes: - Add random to allowed builtins in pyproject.toml - Update imports in pytest_plugin.py - Add migration guide and changelog entries This improves: - Code organization through single-responsibility modules - Maintainability via smaller, focused files - Dependency clarity through explicit imports - Testing capabilities by isolating components - Codebase cleanliness by removing unused constants
2 parents 11748a9 + 6cbfe31 commit 7ac0f21

17 files changed

+540
-363
lines changed

CHANGES

+35
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,41 @@ $ pip install --user --upgrade --pre libtmux
1515

1616
- _Future release notes will be placed here_
1717

18+
### Breaking Changes
19+
20+
#### Test helpers: Refactor
21+
22+
Test helper functionality has been split into focused modules (#XXX):
23+
24+
- `libtmux.test` module split into:
25+
- `libtmux.test.constants`: Test-related constants (`TEST_SESSION_PREFIX`, etc.)
26+
- `libtmux.test.environment`: Environment variable mocking
27+
- `libtmux.test.random`: Random string generation utilities
28+
- `libtmux.test.temporary`: Temporary session/window management
29+
30+
**Breaking**: Import paths have changed. Update imports:
31+
32+
```python
33+
# Old (0.45.x and earlier)
34+
from libtmux.test import (
35+
TEST_SESSION_PREFIX,
36+
get_test_session_name,
37+
get_test_window_name,
38+
namer,
39+
temp_session,
40+
temp_window,
41+
EnvironmentVarGuard,
42+
)
43+
```
44+
45+
```python
46+
# New (0.46.0+)
47+
from libtmux.test.constants import TEST_SESSION_PREFIX
48+
from libtmux.test.environment import EnvironmentVarGuard
49+
from libtmux.test.random import get_test_session_name, get_test_window_name, namer
50+
from libtmux.test.temporary import temp_session, temp_window
51+
```
52+
1853
### Development
1954

2055
- CI: Check for runtime dependencies (#574)

MIGRATION

+35
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,41 @@ _Detailed migration steps for the next version will be posted here._
2525

2626
<!-- To the maintainers and contributors: please add migration details for the upcoming release here -->
2727

28+
## libtmux 0.45.x (Yet to be released)
29+
30+
### Test helpers: Module moves
31+
32+
Test helper functionality has been split into focused modules (#XXX):
33+
34+
- `libtmux.test` module split into:
35+
- `libtmux.test.constants`: Test-related constants (`TEST_SESSION_PREFIX`, etc.)
36+
- `libtmux.test.environment`: Environment variable mocking
37+
- `libtmux.test.random`: Random string generation utilities
38+
- `libtmux.test.temporary`: Temporary session/window management
39+
40+
**Breaking**: Import paths have changed. Update imports:
41+
42+
```python
43+
# Old (0.45.x and earlier)
44+
from libtmux.test import (
45+
TEST_SESSION_PREFIX,
46+
get_test_session_name,
47+
get_test_window_name,
48+
namer,
49+
temp_session,
50+
temp_window,
51+
EnvironmentVarGuard,
52+
)
53+
```
54+
55+
```python
56+
# New (0.46.0+)
57+
from libtmux.test.constants import TEST_SESSION_PREFIX
58+
from libtmux.test.environment import EnvironmentVarGuard
59+
from libtmux.test.random import get_test_session_name, get_test_window_name, namer
60+
from libtmux.test.temporary import temp_session, temp_window
61+
```
62+
2863
## 0.35.0: Commands require explicit targets (2024-03-17)
2964

3065
### Commands require explicit targets (#535)

pyproject.toml

+1
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ required-imports = [
197197
[tool.ruff.lint.flake8-builtins]
198198
builtins-allowed-modules = [
199199
"dataclasses",
200+
"random",
200201
"types",
201202
]
202203

src/libtmux/pytest_plugin.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313

1414
from libtmux import exc
1515
from libtmux.server import Server
16-
from libtmux.test import TEST_SESSION_PREFIX, get_test_session_name, namer
16+
from libtmux.test.constants import TEST_SESSION_PREFIX
17+
from libtmux.test.random import get_test_session_name, namer
1718

1819
if t.TYPE_CHECKING:
1920
import pathlib

0 commit comments

Comments
 (0)