Skip to content

Commit 086852c

Browse files
Merge pull request #33 from osmo-tool/op
Op
2 parents 119bf0f + 5d8f16e commit 086852c

7 files changed

Lines changed: 25 additions & 32 deletions

File tree

doc/architecture_improvements.md

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -761,14 +761,6 @@ class LazyModelCollector:
761761
if self._steps is None:
762762
self._steps = self._discover_steps()
763763
return self._steps
764-
765-
@lru_cache(maxsize=128)
766-
def evaluate_guard(self, step_name: str) -> bool:
767-
"""Evaluate guard with caching."""
768-
guard = self._guards.get(f"guard_{step_name}")
769-
if guard is None:
770-
return True
771-
return guard(self.model)
772764
```
773765

774766
### 6.2 Algorithm Optimizations

license_to_commit.sh

100644100755
File mode changed.

pyosmo/decorators.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,21 +101,21 @@ def can_process(self) -> bool:
101101
# Inline guard - return a decorator that attaches the guard to the step
102102
guard_func = step_name_or_func
103103

104-
def decorator(func: Callable[..., Any]) -> Callable[..., Any]:
104+
def inline_decorator(func: Callable[..., Any]) -> Callable[..., Any]:
105105
func._osmo_guard_inline = guard_func # type: ignore[attr-defined]
106106
func._osmo_guard_invert = invert # type: ignore[attr-defined]
107107
return func
108108

109-
return decorator
109+
return inline_decorator
110110

111111
# Named guard
112-
def decorator(func: Callable[..., Any]) -> Callable[..., Any]:
112+
def named_decorator(func: Callable[..., Any]) -> Callable[..., Any]:
113113
func._osmo_guard = True # type: ignore[attr-defined]
114114
func._osmo_guard_for = step_name_or_func # type: ignore[attr-defined]
115115
func._osmo_guard_invert = invert # type: ignore[attr-defined]
116116
return func
117117

118-
return decorator
118+
return named_decorator
119119

120120

121121
def pre(step_name: str) -> Callable[[F], F]:

pyosmo/model.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,13 @@ def _find_decorator_guard(self) -> Optional['ModelFunction']:
108108
"""Find a guard method decorated with @guard("step_name") for this step."""
109109
for attr_name in dir(self.object_instance):
110110
method = getattr(self.object_instance, attr_name)
111-
if callable(method) and hasattr(method, '_osmo_guard') and hasattr(method, '_osmo_guard_for'):
112-
# Check if this guard is for our step
113-
if method._osmo_guard_for == self.name:
114-
return ModelFunction(attr_name, self.object_instance)
111+
if (
112+
callable(method)
113+
and hasattr(method, '_osmo_guard')
114+
and hasattr(method, '_osmo_guard_for')
115+
and method._osmo_guard_for == self.name
116+
):
117+
return ModelFunction(attr_name, self.object_instance)
115118
return None
116119

117120
@property

pyosmo/tests/test_decorators.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ def __init__(self):
162162
def process(self):
163163
self.process_called = True
164164

165-
@guard("process")
165+
@guard('process')
166166
def can_process(self) -> bool:
167167
return self.ready
168168

@@ -207,7 +207,8 @@ def other_action(self):
207207

208208
model = InlineGuardModel()
209209
osmo = Osmo(model)
210-
osmo.test_end_condition = Length(10)
210+
osmo.seed = 42
211+
osmo.test_end_condition = Length(20)
211212

212213
osmo.run()
213214

@@ -227,7 +228,7 @@ def __init__(self):
227228
def action(self):
228229
self.action_called = True
229230

230-
@guard("action", invert=True)
231+
@guard('action', invert=True)
231232
def is_blocked(self) -> bool:
232233
return self.blocked
233234

@@ -262,11 +263,11 @@ def login(self):
262263
def checkout(self):
263264
pass
264265

265-
@guard("login")
266+
@guard('login')
266267
def can_login(self) -> bool:
267268
return not self.logged_in
268269

269-
@guard("checkout")
270+
@guard('checkout')
270271
def can_checkout(self) -> bool:
271272
return self.logged_in and self.has_items
272273

@@ -305,7 +306,7 @@ def __init__(self):
305306
def action_a(self):
306307
pass
307308

308-
@guard("action_a")
309+
@guard('action_a')
309310
def guard_for_a(self) -> bool:
310311
return self.flag_a
311312

pyproject.toml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[build-system]
2-
requires = ["setuptools>=45", "wheel", "setuptools-scm[toml]>=6.2"]
2+
requires = ["setuptools>=77.0.0", "wheel"]
33
build-backend = "setuptools.build_meta"
44

55
[project]
@@ -8,7 +8,7 @@ version = "0.2.2"
88
description = "pyosmo - a model-based testing tool"
99
readme = "README.md"
1010
requires-python = ">=3.11"
11-
license = {text = "MIT"}
11+
license = "MIT"
1212
authors = [
1313
{name = "Olli-Pekka Puolitaival", email = "oopee1@gmail.com"},
1414
]
@@ -18,7 +18,6 @@ maintainers = [
1818
classifiers = [
1919
"Development Status :: 4 - Beta",
2020
"Intended Audience :: Developers",
21-
"License :: OSI Approved :: MIT License",
2221
"Programming Language :: Python :: 3",
2322
"Programming Language :: Python :: 3.11",
2423
"Programming Language :: Python :: 3.12",
@@ -27,13 +26,13 @@ classifiers = [
2726
]
2827
dependencies = [
2928
"click",
30-
"mypy>=1.18.2",
31-
"pytest>=9.0.0",
3229
]
3330

3431
[project.optional-dependencies]
3532
dev = [
3633
"pytest>=7.0",
34+
"mypy>=1.18.2",
35+
"pytest>=9.0.0",
3736
"hypothesis>=6.0",
3837
"ruff>=0.1.0",
3938
"mypy>=1.0",

uv.lock

Lines changed: 3 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)