Skip to content

Commit e07ebf9

Browse files
committed
refactor!(test[random]) Move helpers to test.random
1 parent d3ea0f9 commit e07ebf9

File tree

7 files changed

+54
-34
lines changed

7 files changed

+54
-34
lines changed

src/libtmux/pytest_plugin.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@
1313

1414
from libtmux import exc
1515
from libtmux.server import Server
16-
from libtmux.test import get_test_session_name, namer
16+
from libtmux.test import get_test_session_name
1717
from libtmux.test.constants import TEST_SESSION_PREFIX
18+
from libtmux.test.random import namer
1819

1920
if t.TYPE_CHECKING:
2021
import pathlib

src/libtmux/test/__init__.py

Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
TEST_SESSION_PREFIX,
1818
)
1919

20+
from .random import namer
21+
2022
logger = logging.getLogger(__name__)
2123

2224
if t.TYPE_CHECKING:
@@ -34,35 +36,6 @@
3436
from typing_extensions import Self
3537

3638

37-
class RandomStrSequence:
38-
"""Factory to generate random string."""
39-
40-
def __init__(
41-
self,
42-
characters: str = "abcdefghijklmnopqrstuvwxyz0123456789_",
43-
) -> None:
44-
"""Create a random letter / number generator. 8 chars in length.
45-
46-
>>> rng = RandomStrSequence()
47-
>>> next(rng)
48-
'...'
49-
>>> len(next(rng))
50-
8
51-
>>> type(next(rng))
52-
<class 'str'>
53-
"""
54-
self.characters: str = characters
55-
56-
def __iter__(self) -> RandomStrSequence:
57-
"""Return self."""
58-
return self
59-
60-
def __next__(self) -> str:
61-
"""Return next random string."""
62-
return "".join(random.sample(self.characters, k=8))
63-
64-
65-
namer = RandomStrSequence()
6639
current_dir = pathlib.Path(__file__)
6740
example_dir = current_dir.parent / "examples"
6841
fixtures_dir = current_dir / "fixtures"

src/libtmux/test/random.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
"""Random helpers for libtmux and downstream libtmux libraries."""
2+
3+
from __future__ import annotations
4+
5+
import logging
6+
import random
7+
import typing as t
8+
9+
logger = logging.getLogger(__name__)
10+
11+
if t.TYPE_CHECKING:
12+
import sys
13+
14+
if sys.version_info >= (3, 11):
15+
pass
16+
17+
18+
class RandomStrSequence:
19+
"""Factory to generate random string."""
20+
21+
def __init__(
22+
self,
23+
characters: str = "abcdefghijklmnopqrstuvwxyz0123456789_",
24+
) -> None:
25+
"""Create a random letter / number generator. 8 chars in length.
26+
27+
>>> rng = RandomStrSequence()
28+
>>> next(rng)
29+
'...'
30+
>>> len(next(rng))
31+
8
32+
>>> type(next(rng))
33+
<class 'str'>
34+
"""
35+
self.characters: str = characters
36+
37+
def __iter__(self) -> RandomStrSequence:
38+
"""Return self."""
39+
return self
40+
41+
def __next__(self) -> str:
42+
"""Return next random string."""
43+
return "".join(random.sample(self.characters, k=8))
44+
45+
46+
namer = RandomStrSequence()

tests/legacy_api/test_session.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
from libtmux.common import has_gte_version, has_lt_version
1313
from libtmux.pane import Pane
1414
from libtmux.session import Session
15-
from libtmux.test import namer
1615
from libtmux.test.constants import TEST_SESSION_PREFIX
16+
from libtmux.test.random import namer
1717
from libtmux.window import Window
1818

1919
if t.TYPE_CHECKING:

tests/legacy_api/test_tmuxobject.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77

88
from libtmux.pane import Pane
99
from libtmux.session import Session
10-
from libtmux.test import namer
1110
from libtmux.test.constants import TEST_SESSION_PREFIX
11+
from libtmux.test.random import namer
1212
from libtmux.window import Window
1313

1414
if t.TYPE_CHECKING:

tests/test_session.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
from libtmux.constants import WindowDirection
1414
from libtmux.pane import Pane
1515
from libtmux.session import Session
16-
from libtmux.test import namer
1716
from libtmux.test.constants import TEST_SESSION_PREFIX
17+
from libtmux.test.random import namer
1818
from libtmux.window import Window
1919

2020
if t.TYPE_CHECKING:

tests/test_tmuxobject.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77

88
from libtmux.pane import Pane
99
from libtmux.session import Session
10-
from libtmux.test import namer
1110
from libtmux.test.constants import TEST_SESSION_PREFIX
11+
from libtmux.test.random import namer
1212
from libtmux.window import Window
1313

1414
if t.TYPE_CHECKING:

0 commit comments

Comments
 (0)