Skip to content

Commit e8bf689

Browse files
committed
refactor(test fixtures): Use basic dataclass
1 parent af55803 commit e8bf689

File tree

2 files changed

+33
-12
lines changed

2 files changed

+33
-12
lines changed

tests/fixtures/structures.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import dataclasses
2+
import typing as t
3+
4+
5+
@dataclasses.dataclass
6+
class TestConfigData:
7+
expand1: t.Any
8+
expand2: t.Any
9+
expand_blank: t.Any
10+
sampleconfig: t.Any
11+
shell_command_before: t.Any
12+
shell_command_before_session: t.Any
13+
trickle: t.Any

tests/test_config.py

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""Test for tmuxp configuration import, inlining, expanding and export."""
22
import os
33
import pathlib
4+
import types
45
import typing
56
from typing import Union
67

@@ -13,7 +14,7 @@
1314
from .constants import EXAMPLE_PATH
1415

1516
if typing.TYPE_CHECKING:
16-
from .fixtures import config as ConfigFixture
17+
from .fixtures.structures import TestConfigData
1718

1819

1920
@pytest.fixture
@@ -23,9 +24,16 @@ def config_fixture():
2324
pytest setup (conftest.py) patches os.environ["HOME"], delay execution of
2425
os.path.expanduser until here.
2526
"""
26-
from .fixtures import config as config_fixture
27-
28-
return config_fixture
27+
from .fixtures import config as test_config_data
28+
from .fixtures.structures import TestConfigData
29+
30+
return TestConfigData(
31+
**{
32+
k: v
33+
for k, v in test_config_data.__dict__.items()
34+
if isinstance(v, types.ModuleType)
35+
}
36+
)
2937

3038

3139
def load_yaml(path: Union[str, pathlib.Path]) -> str:
@@ -44,7 +52,7 @@ def load_config(path: Union[str, pathlib.Path]) -> str:
4452
)
4553

4654

47-
def test_export_json(tmp_path: pathlib.Path, config_fixture: "ConfigFixture"):
55+
def test_export_json(tmp_path: pathlib.Path, config_fixture: "TestConfigData"):
4856
json_config_file = tmp_path / "config.json"
4957

5058
configparser = kaptan.Kaptan()
@@ -59,7 +67,7 @@ def test_export_json(tmp_path: pathlib.Path, config_fixture: "ConfigFixture"):
5967
assert config_fixture.sampleconfig.sampleconfigdict == new_config_data
6068

6169

62-
def test_export_yaml(tmp_path: pathlib.Path, config_fixture: "ConfigFixture"):
70+
def test_export_yaml(tmp_path: pathlib.Path, config_fixture: "TestConfigData"):
6371
yaml_config_file = tmp_path / "config.yaml"
6472

6573
configparser = kaptan.Kaptan()
@@ -103,13 +111,13 @@ def test_scan_config(tmp_path: pathlib.Path):
103111
assert len(configs) == files
104112

105113

106-
def test_config_expand1(config_fixture: "ConfigFixture"):
114+
def test_config_expand1(config_fixture: "TestConfigData"):
107115
"""Expand shell commands from string to list."""
108116
test_config = config.expand(config_fixture.expand1.before_config)
109117
assert test_config == config_fixture.expand1.after_config()
110118

111119

112-
def test_config_expand2(config_fixture: "ConfigFixture"):
120+
def test_config_expand2(config_fixture: "TestConfigData"):
113121
"""Expand shell commands from string to list."""
114122
unexpanded_dict = load_yaml(config_fixture.expand2.unexpanded_yaml())
115123
expanded_dict = load_yaml(config_fixture.expand2.expanded_yaml())
@@ -228,7 +236,7 @@ def test_inheritance_config():
228236
assert config == inheritance_config_after
229237

230238

231-
def test_shell_command_before(config_fixture: "ConfigFixture"):
239+
def test_shell_command_before(config_fixture: "TestConfigData"):
232240
"""Config inheritance for the nested 'start_command'."""
233241
test_config = config_fixture.shell_command_before.config_unexpanded
234242
test_config = config.expand(test_config)
@@ -239,7 +247,7 @@ def test_shell_command_before(config_fixture: "ConfigFixture"):
239247
assert test_config == config_fixture.shell_command_before.config_after()
240248

241249

242-
def test_in_session_scope(config_fixture: "ConfigFixture"):
250+
def test_in_session_scope(config_fixture: "TestConfigData"):
243251
sconfig = load_yaml(config_fixture.shell_command_before_session.before)
244252

245253
config.validate_schema(sconfig)
@@ -250,7 +258,7 @@ def test_in_session_scope(config_fixture: "ConfigFixture"):
250258
)
251259

252260

253-
def test_trickle_relative_start_directory(config_fixture: "ConfigFixture"):
261+
def test_trickle_relative_start_directory(config_fixture: "TestConfigData"):
254262
test_config = config.trickle(config_fixture.trickle.before)
255263
assert test_config == config_fixture.trickle.expected
256264

@@ -273,7 +281,7 @@ def test_trickle_window_with_no_pane_config():
273281
}
274282

275283

276-
def test_expands_blank_panes(config_fixture: "ConfigFixture"):
284+
def test_expands_blank_panes(config_fixture: "TestConfigData"):
277285
"""Expand blank config into full form.
278286
279287
Handle ``NoneType`` and 'blank'::

0 commit comments

Comments
 (0)