Skip to content

Commit 0c59ff6

Browse files
committed
Test config selection modes
1 parent 501d80b commit 0c59ff6

2 files changed

Lines changed: 78 additions & 0 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ The `CI` workflow runs daily and on pushes. It checks the OptiProfiler adapter l
3535
- selecting a small set of representative `u`, `b`, `l`, and `n` problems;
3636
- loading each selected problem through `s2mpj_load`;
3737
- evaluating `fun`, `cub`, and `ceq` at the initial point;
38+
- checking `variable_size` and `test_feasibility_problems` environment overrides;
3839
- sampling a few additional small problems each day with at most two numerical-library threads.
3940

4041
Locally, from this repository:

tests/test_s2mpj_python.py

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
from datetime import date
44
from pathlib import Path
5+
from contextlib import contextmanager
56
import math
67
import os
78
import random
@@ -30,6 +31,24 @@
3031
REPRESENTATIVE_PROBLEMS = ["ALLINITU", "ALLINIT", "ALSOTAME", "ALLINITA"]
3132

3233

34+
@contextmanager
35+
def _temporary_env(**updates):
36+
previous = {key: os.environ.get(key) for key in updates}
37+
try:
38+
for key, value in updates.items():
39+
if value is None:
40+
os.environ.pop(key, None)
41+
else:
42+
os.environ[key] = str(value)
43+
yield
44+
finally:
45+
for key, value in previous.items():
46+
if value is None:
47+
os.environ.pop(key, None)
48+
else:
49+
os.environ[key] = value
50+
51+
3352
def _as_array(value):
3453
if value is None:
3554
return np.empty(0)
@@ -96,6 +115,64 @@ def test_daily_random_small_problem_sample(self):
96115
with self.subTest(problem=problem_name):
97116
_assert_problem_contract(self, problem_name)
98117

118+
def test_config_environment_overrides_variable_size(self):
119+
options = {
120+
"ptype": "ubln",
121+
"maxdim": 5,
122+
"maxb": 20,
123+
"maxlcon": 20,
124+
"maxnlcon": 20,
125+
"maxcon": 20,
126+
}
127+
with _temporary_env(
128+
S2MPJ_VARIABLE_SIZE=None,
129+
S2MPJ_TEST_FEASIBILITY_PROBLEMS=None,
130+
):
131+
default_names = s2mpj_select(dict(options))
132+
with _temporary_env(
133+
S2MPJ_VARIABLE_SIZE="all",
134+
S2MPJ_TEST_FEASIBILITY_PROBLEMS="0",
135+
):
136+
all_names = s2mpj_select(dict(options))
137+
138+
self.assertGreater(len(all_names), len(default_names))
139+
self.assertIn("CHEBYQAD_2", all_names)
140+
self.assertNotIn("CHEBYQAD_2", default_names)
141+
142+
def test_config_environment_overrides_feasibility_selection(self):
143+
options = {
144+
"ptype": "ubln",
145+
"maxdim": 5,
146+
"maxb": 20,
147+
"maxlcon": 20,
148+
"maxnlcon": 20,
149+
"maxcon": 20,
150+
}
151+
with _temporary_env(
152+
S2MPJ_VARIABLE_SIZE="default",
153+
S2MPJ_TEST_FEASIBILITY_PROBLEMS="1",
154+
):
155+
feasibility_names = s2mpj_select(dict(options))
156+
with _temporary_env(
157+
S2MPJ_VARIABLE_SIZE="default",
158+
S2MPJ_TEST_FEASIBILITY_PROBLEMS="2",
159+
):
160+
all_names = s2mpj_select(dict(options))
161+
162+
self.assertIn("ARGAUSS", feasibility_names)
163+
self.assertNotIn("ALLINITU", feasibility_names)
164+
self.assertIn("ARGAUSS", all_names)
165+
self.assertIn("ALLINITU", all_names)
166+
167+
def test_config_environment_rejects_invalid_values(self):
168+
options = {"ptype": "u", "maxdim": 5}
169+
with _temporary_env(S2MPJ_VARIABLE_SIZE="not-a-mode"):
170+
with self.assertRaises(ValueError):
171+
s2mpj_select(dict(options))
172+
with _temporary_env(S2MPJ_TEST_FEASIBILITY_PROBLEMS="3"):
173+
with self.assertRaises(ValueError):
174+
s2mpj_select(dict(options))
175+
99176

100177
if __name__ == "__main__":
101178
unittest.main()

0 commit comments

Comments
 (0)