Skip to content

Commit 145c051

Browse files
BrianMichelltasansal
authored andcommitted
Fix pre-commit issues
1 parent 879ddca commit 145c051

File tree

1 file changed

+77
-48
lines changed

1 file changed

+77
-48
lines changed

tests/unit/test_environment.py

Lines changed: 77 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""Tests for the MDIO Environment API."""
22

33
import os
4+
from collections.abc import Callable
45
from unittest.mock import patch
56

67
import pytest
@@ -12,97 +13,125 @@
1213
class TestEnvironment:
1314
"""Test the Environment API class methods."""
1415

15-
@pytest.mark.parametrize("method,expected_type", [
16-
(Environment.export_cpus, int),
17-
(Environment.import_cpus, int),
18-
(Environment.grid_sparsity_ratio_warn, float),
19-
(Environment.grid_sparsity_ratio_limit, float),
20-
(Environment.save_segy_file_header, bool),
21-
(Environment.raw_headers, bool),
22-
(Environment.ignore_checks, bool),
23-
(Environment.cloud_native, bool),
24-
])
25-
def test_default_values(self, method, expected_type):
16+
@pytest.mark.parametrize(
17+
("method", "expected_type"),
18+
[
19+
(Environment.export_cpus, int),
20+
(Environment.import_cpus, int),
21+
(Environment.grid_sparsity_ratio_warn, float),
22+
(Environment.grid_sparsity_ratio_limit, float),
23+
(Environment.save_segy_file_header, bool),
24+
(Environment.raw_headers, bool),
25+
(Environment.ignore_checks, bool),
26+
(Environment.cloud_native, bool),
27+
],
28+
)
29+
def test_default_values(self, method: Callable[[], object], expected_type: type) -> None:
2630
"""Test all methods return correct types with defaults."""
2731
with patch.dict(os.environ, {}, clear=True):
2832
result = method()
2933
assert isinstance(result, expected_type)
3034

31-
def test_mdio_segy_spec_defaults_to_none(self):
35+
def test_mdio_segy_spec_defaults_to_none(self) -> None:
3236
"""Test mdio_segy_spec returns None by default."""
3337
with patch.dict(os.environ, {}, clear=True):
3438
result = Environment.mdio_segy_spec()
3539
assert result is None
3640

37-
@pytest.mark.parametrize("env_var,value,method,expected", [
38-
("MDIO__EXPORT__CPU_COUNT", "8", Environment.export_cpus, 8),
39-
("MDIO__IMPORT__CPU_COUNT", "4", Environment.import_cpus, 4),
40-
("MDIO__GRID__SPARSITY_RATIO_WARN", "3.5", Environment.grid_sparsity_ratio_warn, 3.5),
41-
("MDIO__GRID__SPARSITY_RATIO_LIMIT", "15.0", Environment.grid_sparsity_ratio_limit, 15.0),
42-
("MDIO__SEGY__SPEC", "/path/to/spec.json", Environment.mdio_segy_spec, "/path/to/spec.json"),
43-
])
44-
def test_env_var_overrides(self, env_var, value, method, expected):
41+
@pytest.mark.parametrize(
42+
("env_var", "value", "method", "expected"),
43+
[
44+
("MDIO__EXPORT__CPU_COUNT", "8", Environment.export_cpus, 8),
45+
("MDIO__IMPORT__CPU_COUNT", "4", Environment.import_cpus, 4),
46+
("MDIO__GRID__SPARSITY_RATIO_WARN", "3.5", Environment.grid_sparsity_ratio_warn, 3.5),
47+
("MDIO__GRID__SPARSITY_RATIO_LIMIT", "15.0", Environment.grid_sparsity_ratio_limit, 15.0),
48+
("MDIO__SEGY__SPEC", "/path/to/spec.json", Environment.mdio_segy_spec, "/path/to/spec.json"),
49+
],
50+
)
51+
def test_env_var_overrides(self, env_var: str, value: str, method: Callable[[], object], expected: object) -> None:
4552
"""Test environment variables override defaults."""
4653
with patch.dict(os.environ, {env_var: value}):
4754
result = method()
4855
assert result == expected
4956

50-
@pytest.mark.parametrize("method,env_var", [
51-
(Environment.save_segy_file_header, "MDIO__IMPORT__SAVE_SEGY_FILE_HEADER"),
52-
(Environment.raw_headers, "MDIO__IMPORT__RAW_HEADERS"),
53-
(Environment.ignore_checks, "MDIO_IGNORE_CHECKS"),
54-
(Environment.cloud_native, "MDIO__IMPORT__CLOUD_NATIVE"),
55-
])
56-
@pytest.mark.parametrize("value,expected", [
57-
("1", True), ("true", True), ("yes", True), ("on", True),
58-
("0", False), ("false", False), ("no", False), ("off", False),
59-
("anything_else", False), ("", False),
60-
])
61-
def test_boolean_parsing(self, method, env_var, value, expected):
57+
@pytest.mark.parametrize(
58+
("method", "env_var"),
59+
[
60+
(Environment.save_segy_file_header, "MDIO__IMPORT__SAVE_SEGY_FILE_HEADER"),
61+
(Environment.raw_headers, "MDIO__IMPORT__RAW_HEADERS"),
62+
(Environment.ignore_checks, "MDIO_IGNORE_CHECKS"),
63+
(Environment.cloud_native, "MDIO__IMPORT__CLOUD_NATIVE"),
64+
],
65+
)
66+
@pytest.mark.parametrize(
67+
("value", "expected"),
68+
[
69+
("1", True),
70+
("true", True),
71+
("yes", True),
72+
("on", True),
73+
("0", False),
74+
("false", False),
75+
("no", False),
76+
("off", False),
77+
("anything_else", False),
78+
("", False),
79+
],
80+
)
81+
def test_boolean_parsing(self, method: Callable[[], bool], env_var: str, value: str, expected: bool) -> None:
6282
"""Test boolean parsing for all boolean methods."""
6383
with patch.dict(os.environ, {env_var: value}):
6484
result = method()
6585
assert result is expected
6686

67-
@pytest.mark.parametrize("method,env_var", [
68-
(Environment.export_cpus, "MDIO__EXPORT__CPU_COUNT"),
69-
(Environment.import_cpus, "MDIO__IMPORT__CPU_COUNT"),
70-
])
87+
@pytest.mark.parametrize(
88+
("method", "env_var"),
89+
[
90+
(Environment.export_cpus, "MDIO__EXPORT__CPU_COUNT"),
91+
(Environment.import_cpus, "MDIO__IMPORT__CPU_COUNT"),
92+
],
93+
)
7194
@pytest.mark.parametrize("invalid_value", ["invalid", "not_a_number", ""])
72-
def test_int_validation_errors(self, method, env_var, invalid_value):
95+
def test_int_validation_errors(self, method: Callable[[], int], env_var: str, invalid_value: str) -> None:
7396
"""Test integer methods raise errors for invalid values."""
7497
with patch.dict(os.environ, {env_var: invalid_value}):
7598
with pytest.raises(EnvironmentFormatError) as exc_info:
7699
method()
77100
assert env_var in str(exc_info.value)
78101
assert "int" in str(exc_info.value)
79102

80-
@pytest.mark.parametrize("method,env_var", [
81-
(Environment.grid_sparsity_ratio_warn, "MDIO__GRID__SPARSITY_RATIO_WARN"),
82-
(Environment.grid_sparsity_ratio_limit, "MDIO__GRID__SPARSITY_RATIO_LIMIT"),
83-
])
103+
@pytest.mark.parametrize(
104+
("method", "env_var"),
105+
[
106+
(Environment.grid_sparsity_ratio_warn, "MDIO__GRID__SPARSITY_RATIO_WARN"),
107+
(Environment.grid_sparsity_ratio_limit, "MDIO__GRID__SPARSITY_RATIO_LIMIT"),
108+
],
109+
)
84110
@pytest.mark.parametrize("invalid_value", ["invalid", "not_a_number", ""])
85-
def test_float_validation_errors(self, method, env_var, invalid_value):
111+
def test_float_validation_errors(self, method: Callable[[], float], env_var: str, invalid_value: str) -> None:
86112
"""Test float methods raise errors for invalid values."""
87113
with patch.dict(os.environ, {env_var: invalid_value}):
88114
with pytest.raises(EnvironmentFormatError) as exc_info:
89115
method()
90116
assert env_var in str(exc_info.value)
91117
assert "float" in str(exc_info.value)
92118

93-
def test_environment_isolation(self):
119+
def test_environment_isolation(self) -> None:
94120
"""Test that environment changes don't affect other tests."""
95121
original_values = {
96122
"cpus": Environment.export_cpus(),
97123
"ratio": Environment.grid_sparsity_ratio_warn(),
98124
"bool": Environment.save_segy_file_header(),
99125
}
100126

101-
with patch.dict(os.environ, {
102-
"MDIO__EXPORT__CPU_COUNT": "99",
103-
"MDIO__GRID__SPARSITY_RATIO_WARN": "99.9",
104-
"MDIO__IMPORT__SAVE_SEGY_FILE_HEADER": "true"
105-
}):
127+
with patch.dict(
128+
os.environ,
129+
{
130+
"MDIO__EXPORT__CPU_COUNT": "99",
131+
"MDIO__GRID__SPARSITY_RATIO_WARN": "99.9",
132+
"MDIO__IMPORT__SAVE_SEGY_FILE_HEADER": "true",
133+
},
134+
):
106135
assert Environment.export_cpus() == 99
107136
assert Environment.grid_sparsity_ratio_warn() == 99.9
108137
assert Environment.save_segy_file_header() is True

0 commit comments

Comments
 (0)