Skip to content

Commit 4a4ff08

Browse files
committed
refactor(tests): Move constants to tests.constants
1 parent 302caa3 commit 4a4ff08

File tree

7 files changed

+19
-25
lines changed

7 files changed

+19
-25
lines changed

tests/__init__.py

-11
Original file line numberDiff line numberDiff line change
@@ -1,11 +0,0 @@
1-
"""Tests for tmuxp.
2-
3-
tmuxp.tests
4-
~~~~~~~~~~~
5-
6-
"""
7-
import pathlib
8-
9-
TESTS_PATH = pathlib.Path(__file__).parent
10-
EXAMPLE_PATH = TESTS_PATH.parent / "examples"
11-
FIXTURES_PATH = TESTS_PATH / "fixtures"

tests/constants.py

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import pathlib
2+
3+
TESTS_PATH = pathlib.Path(__file__).parent
4+
EXAMPLE_PATH = TESTS_PATH.parent / "examples"
5+
FIXTURE_PATH = TESTS_PATH / "fixtures"

tests/fixtures/utils.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import pathlib
22

3-
FIXTURE_PATH = pathlib.Path(__file__).parent
3+
from ..constants import FIXTURE_PATH
44

55

66
def read_config_file(_file): # return fixture data, relative to __file__

tests/test_cli.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@
2828
)
2929
from tmuxp.workspacebuilder import WorkspaceBuilder
3030

31+
from .constants import FIXTURE_PATH
3132
from .fixtures import utils as test_utils
32-
from .fixtures._util import FIXTURE_PATH
3333

3434

3535
def test_creates_config_dir_not_exists(tmp_path: pathlib.Path):

tests/test_config.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
from tmuxp import config, exc
1212

13-
from . import EXAMPLE_PATH
13+
from .constants import EXAMPLE_PATH
1414

1515
if typing.TYPE_CHECKING:
1616
from .fixtures import config as ConfigFixture

tests/test_util.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
from tmuxp.exc import BeforeLoadScriptError, BeforeLoadScriptNotExists
66
from tmuxp.util import get_session, run_before_script
77

8-
from . import FIXTURES_PATH
8+
from .constants import FIXTURE_PATH
99

1010

1111
def test_raise_BeforeLoadScriptNotExists_if_not_exists():
12-
script_file = FIXTURES_PATH / "script_noexists.sh"
12+
script_file = FIXTURE_PATH / "script_noexists.sh"
1313

1414
with pytest.raises(BeforeLoadScriptNotExists):
1515
run_before_script(script_file)
@@ -19,30 +19,30 @@ def test_raise_BeforeLoadScriptNotExists_if_not_exists():
1919

2020

2121
def test_raise_BeforeLoadScriptError_if_retcode():
22-
script_file = FIXTURES_PATH / "script_failed.sh"
22+
script_file = FIXTURE_PATH / "script_failed.sh"
2323

2424
with pytest.raises(BeforeLoadScriptError):
2525
run_before_script(script_file)
2626

2727

2828
def test_return_stdout_if_ok(capsys):
29-
script_file = FIXTURES_PATH / "script_complete.sh"
29+
script_file = FIXTURE_PATH / "script_complete.sh"
3030

3131
run_before_script(script_file)
3232
out, err = capsys.readouterr()
3333
assert "hello" in out
3434

3535

3636
def test_beforeload_returncode():
37-
script_file = FIXTURES_PATH / "script_failed.sh"
37+
script_file = FIXTURE_PATH / "script_failed.sh"
3838

3939
with pytest.raises(exc.BeforeLoadScriptError) as excinfo:
4040
run_before_script(script_file)
4141
assert excinfo.match(r"113")
4242

4343

4444
def test_beforeload_returns_stderr_messages():
45-
script_file = FIXTURES_PATH / "script_failed.sh"
45+
script_file = FIXTURE_PATH / "script_failed.sh"
4646

4747
with pytest.raises(exc.BeforeLoadScriptError) as excinfo:
4848
run_before_script(script_file)

tests/test_workspacebuilder.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
from tmuxp.cli import load_plugins
1717
from tmuxp.workspacebuilder import WorkspaceBuilder
1818

19-
from . import EXAMPLE_PATH, FIXTURES_PATH
19+
from .constants import EXAMPLE_PATH, FIXTURE_PATH
2020
from .fixtures import utils as test_utils
2121

2222

@@ -597,7 +597,7 @@ def test_before_load_throw_error_if_retcode_error(server):
597597
)
598598
sconfig = kaptan.Kaptan(handler="yaml")
599599
yaml = config_script_fails.format(
600-
script_failed=FIXTURES_PATH / "script_failed.sh",
600+
script_failed=FIXTURE_PATH / "script_failed.sh",
601601
)
602602

603603
sconfig = sconfig.import_config(yaml).get()
@@ -622,7 +622,7 @@ def test_before_load_throw_error_if_file_not_exists(server):
622622
)
623623
sconfig = kaptan.Kaptan(handler="yaml")
624624
yaml = config_script_not_exists.format(
625-
script_not_exists=FIXTURES_PATH / "script_not_exists.sh",
625+
script_not_exists=FIXTURE_PATH / "script_not_exists.sh",
626626
)
627627
sconfig = sconfig.import_config(yaml).get()
628628
sconfig = config.expand(sconfig)
@@ -645,7 +645,7 @@ def test_before_load_true_if_test_passes(server):
645645
config_script_completes = test_utils.read_config_file(
646646
"workspacebuilder/config_script_completes.yaml"
647647
)
648-
script_complete_sh = FIXTURES_PATH / "script_complete.sh"
648+
script_complete_sh = FIXTURE_PATH / "script_complete.sh"
649649
assert script_complete_sh.exists()
650650
sconfig = kaptan.Kaptan(handler="yaml")
651651
yaml = config_script_completes.format(
@@ -666,7 +666,7 @@ def test_before_load_true_if_test_passes_with_args(server):
666666
config_script_completes = test_utils.read_config_file(
667667
"workspacebuilder/config_script_completes.yaml"
668668
)
669-
script_complete_sh = FIXTURES_PATH / "script_complete.sh"
669+
script_complete_sh = FIXTURE_PATH / "script_complete.sh"
670670
assert script_complete_sh.exists()
671671
sconfig = kaptan.Kaptan(handler="yaml")
672672
yaml = config_script_completes.format(script_complete=script_complete_sh)

0 commit comments

Comments
 (0)