Skip to content

Commit 584689f

Browse files
fix: Pre-commit
1 parent a303efa commit 584689f

File tree

15 files changed

+84
-3
lines changed

15 files changed

+84
-3
lines changed

src/ansys/tools/common/launcher/config.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ def save_config() -> None:
216216
# Convert to JSON before saving; in this way, errors during
217217
# JSON encoding will not clobber the config file.
218218
config_json = json.dumps(dataclasses.asdict(_CONFIG)["__root__"], indent=2)
219-
with open(file_path, "w") as out_f:
219+
with file_path.open("w") as out_f:
220220
out_f.write(config_json)
221221

222222

@@ -231,7 +231,7 @@ def _load_config() -> _LauncherConfiguration:
231231
config_path = _get_config_path()
232232
if not config_path.exists():
233233
return _LauncherConfiguration(__root__={})
234-
with open(config_path) as in_f:
234+
with config_path.open() as in_f:
235235
return _LauncherConfiguration(__root__={key: _ProductConfig(**val) for key, val in json.load(in_f).items()})
236236

237237

tests/launcher/conftest.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2020
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2121
# SOFTWARE.
22+
"""Conftest module."""
2223

2324
from functools import partial
2425
import importlib.metadata
@@ -39,6 +40,7 @@ def reset_config():
3940
def get_mock_entrypoints_from_plugins(
4041
target_plugins: dict[str, dict[str, LauncherProtocol[LAUNCHER_CONFIG_T]]],
4142
):
43+
"""Get mock entrypoints from plugins."""
4244
res = []
4345
for product_name, launchers in target_plugins.items():
4446
for launch_mode, launcher_kls in launchers.items():
@@ -51,6 +53,8 @@ def get_mock_entrypoints_from_plugins(
5153

5254
@pytest.fixture
5355
def monkeypatch_entrypoints_from_plugins(monkeypatch):
56+
"""Mock entrypoints."""
57+
5458
def inner(target_plugins):
5559
monkeypatch.setattr(
5660
_plugins,

tests/launcher/pkg_with_entrypoint/src/pkg_with_entrypoint/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2020
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2121
# SOFTWARE.
22+
"""Module for entrypoint package."""
2223

2324
from .launcher import Launcher, LauncherConfig
2425

tests/launcher/pkg_with_entrypoint/src/pkg_with_entrypoint/launcher.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2020
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2121
# SOFTWARE.
22+
"""Module for package."""
2223

2324
from dataclasses import dataclass
2425

@@ -27,8 +28,12 @@
2728

2829
@dataclass
2930
class LauncherConfig:
31+
"""Launcher configuration for the package with an entry point."""
32+
3033
pass
3134

3235

3336
class Launcher(interface.LauncherProtocol[LauncherConfig]):
37+
"""Launcher for the package with an entry point."""
38+
3439
CONFIG_MODEL = LauncherConfig

tests/launcher/test_cli/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,4 @@
1919
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2020
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2121
# SOFTWARE.
22+
"""Test CLI module."""

tests/launcher/test_cli/common.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,14 @@
1919
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2020
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2121
# SOFTWARE.
22+
"""Module for common testing functionalities."""
2223

2324
import json
25+
from pathlib import Path
2426

2527

2628
def check_result_config(path, expected):
27-
with open(path) as f:
29+
"""Check result from configuration."""
30+
with Path(path).open() as f:
2831
config = json.load(f)
2932
assert config == expected

tests/launcher/test_cli/conftest.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2020
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2121
# SOFTWARE.
22+
"""Conftest module."""
2223

2324
import pytest
2425

@@ -29,6 +30,7 @@
2930

3031
@pytest.fixture
3132
def temp_config_file(monkeypatch, tmp_path):
33+
"""Fixture to create a temporary configuration file for testing."""
3234
output_path = tmp_path / "config.json"
3335

3436
def get_config_path_patched():

tests/launcher/test_cli/test_multiple_plugins.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2020
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2121
# SOFTWARE.
22+
"""Module for multiple plugins test."""
2223

2324
from dataclasses import dataclass
2425

@@ -38,28 +39,40 @@
3839

3940
@dataclass
4041
class MockConfigA1:
42+
"""Mock config."""
43+
4144
field_a1: int
4245

4346

4447
class MockLauncherA1(interface.LauncherProtocol[MockConfigA1]):
48+
"""Mock launcher."""
49+
4550
CONFIG_MODEL = MockConfigA1
4651

4752

4853
@dataclass
4954
class MockConfigA2:
55+
"""Mock config."""
56+
5057
field_a2: int
5158

5259

5360
class MockLauncherA2(interface.LauncherProtocol[MockConfigA2]):
61+
"""Mock launcher."""
62+
5463
CONFIG_MODEL = MockConfigA2
5564

5665

5766
@dataclass
5867
class MockConfigB1:
68+
"""Mock config."""
69+
5970
field_b1: int
6071

6172

6273
class MockLauncherB1(interface.LauncherProtocol[MockConfigB1]):
74+
"""Mock launcher for testing CLI configuration for product B."""
75+
6376
CONFIG_MODEL = MockConfigB1
6477

6578

@@ -74,10 +87,12 @@ class MockLauncherB1(interface.LauncherProtocol[MockConfigB1]):
7487

7588
@pytest.fixture(autouse=True)
7689
def monkeypatch_entrypoints(monkeypatch_entrypoints_from_plugins):
90+
"""Mock entrypoints for the plugins."""
7791
monkeypatch_entrypoints_from_plugins(PLUGINS)
7892

7993

8094
def test_cli_structure():
95+
"""Test CLI structure."""
8196
command = _cli.build_cli(_plugins.get_all_plugins())
8297
assert "configure" in command.commands
8398
configure_group = command.commands["configure"]
@@ -93,6 +108,7 @@ def test_cli_structure():
93108

94109

95110
def test_configure_single_product_launcher(temp_config_file):
111+
"""Test configuring a single product with a single launcher."""
96112
cli_command = _cli.build_cli(_plugins.get_all_plugins())
97113
runner = CliRunner()
98114
result = runner.invoke(
@@ -113,6 +129,7 @@ def test_configure_single_product_launcher(temp_config_file):
113129

114130

115131
def test_configure_two_product_launchers(temp_config_file):
132+
"""Test configuring two different products with different launch modes."""
116133
cli_command = _cli.build_cli(_plugins.get_all_plugins())
117134
runner = CliRunner()
118135
result = runner.invoke(
@@ -141,6 +158,7 @@ def test_configure_two_product_launchers(temp_config_file):
141158

142159

143160
def test_configure_two_product_launchers_overwrite(temp_config_file):
161+
"""Test configuring two products with overwriting configurations."""
144162
cli_command = _cli.build_cli(_plugins.get_all_plugins())
145163
runner = CliRunner()
146164
result = runner.invoke(
@@ -169,6 +187,7 @@ def test_configure_two_product_launchers_overwrite(temp_config_file):
169187

170188

171189
def test_configure_two_products(temp_config_file):
190+
"""Test configuring two products."""
172191
cli_command = _cli.build_cli(_plugins.get_all_plugins())
173192
runner = CliRunner()
174193
result = runner.invoke(

tests/launcher/test_cli/test_single_plugin.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2020
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2121
# SOFTWARE.
22+
"""Module for testing plugins."""
2223

2324
from dataclasses import dataclass, field
2425

@@ -32,6 +33,8 @@
3233

3334
@dataclass
3435
class MockConfig:
36+
"""Mock configuration for testing CLI."""
37+
3538
int_field: int
3639
str_field: str
3740
json_field: dict[str, str]
@@ -40,6 +43,8 @@ class MockConfig:
4043

4144

4245
class MockLauncher(interface.LauncherProtocol[MockConfig]):
46+
"""Mock launcher for testing CLI configuration."""
47+
4348
CONFIG_MODEL = MockConfig
4449

4550

@@ -64,10 +69,12 @@ class MockLauncher(interface.LauncherProtocol[MockConfig]):
6469

6570
@pytest.fixture
6671
def mock_plugins():
72+
"""Mock plugin for testing CLI."""
6773
return {TEST_PRODUCT: {TEST_LAUNCH_MODE: MockLauncher}}
6874

6975

7076
def test_cli_no_plugins():
77+
"""Test that the CLI is built correctly with no plugins."""
7178
command = _cli.build_cli(dict())
7279
runner = CliRunner()
7380
result = runner.invoke(command, ["configure"])
@@ -76,6 +83,7 @@ def test_cli_no_plugins():
7683

7784

7885
def test_cli_mock_plugin(mock_plugins):
86+
"""Test that the CLI is built correctly with a mock plugin."""
7987
command = _cli.build_cli(mock_plugins)
8088
assert "configure" in command.commands
8189
configure_group = command.commands["configure"]
@@ -135,6 +143,7 @@ def test_cli_mock_plugin(mock_plugins):
135143
],
136144
)
137145
def test_run_cli(temp_config_file, mock_plugins, commands, prompts):
146+
"""Test running the CLI."""
138147
cli_command = _cli.build_cli(mock_plugins)
139148
runner = CliRunner()
140149
result = runner.invoke(
@@ -148,6 +157,7 @@ def test_run_cli(temp_config_file, mock_plugins, commands, prompts):
148157

149158

150159
def test_run_cli_throws_on_incorrect_type(temp_config_file, mock_plugins):
160+
"""Test that the CLI throws an error when a field is given an incorrect type."""
151161
cli_command = _cli.build_cli(mock_plugins)
152162
runner = CliRunner()
153163
result = runner.invoke(

tests/launcher/test_entry_point.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2020
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2121
# SOFTWARE.
22+
"""Module for entry point testing."""
23+
2224
import pkg_with_entrypoint
2325

2426
from ansys.tools.common.launcher._plugins import (
@@ -30,17 +32,20 @@
3032

3133

3234
def test_plugin_found():
35+
"""Test that the plugin is found in the plugin dictionary."""
3336
plugin_dict = get_all_plugins()
3437
assert "pkg_with_entrypoint" in plugin_dict
3538
assert "test_entry_point" in plugin_dict["pkg_with_entrypoint"]
3639

3740

3841
def test_get_launcher():
42+
"""Test that the launcher can be retrieved for a specific product and launch mode."""
3943
launcher = get_launcher(product_name="pkg_with_entrypoint", launch_mode="test_entry_point")
4044
assert launcher.__name__ == "Launcher"
4145

4246

4347
def test_fallback():
48+
"""Test fallback."""
4449
assert get_launch_mode_for(product_name="pkg_with_entrypoint") == "__fallback__"
4550
assert (
4651
get_config_for(product_name="pkg_with_entrypoint", launch_mode="__fallback__")
@@ -50,6 +55,7 @@ def test_fallback():
5055

5156

5257
def test_get_config_model():
58+
"""Test that get_config_model returns the correct configuration model."""
5359
config_model = get_config_model(product_name="pkg_with_entrypoint", launch_mode="test_entry_point")
5460
assert config_model.__name__ == "LauncherConfig"
5561

0 commit comments

Comments
 (0)