Skip to content

Commit d58ac37

Browse files
committed
fix: provide mock implementations for Driver and utility functions when AFL-automation is not installed
1 parent 6bb00b7 commit d58ac37

File tree

1 file changed

+33
-2
lines changed

1 file changed

+33
-2
lines changed

AFL/double_agent/AgentWebAppMixin.py

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,39 @@
66
from importlib.resources import files
77
from jinja2 import Template
88

9-
from AFL.automation.APIServer.Driver import Driver # type: ignore
10-
from AFL.automation.shared.utilities import mpl_plot_to_bytes, xarray_to_bytes
9+
try:
10+
from AFL.automation.APIServer.Driver import Driver # type: ignore
11+
from AFL.automation.shared.utilities import mpl_plot_to_bytes, xarray_to_bytes
12+
except ModuleNotFoundError as exc:
13+
# Allow unit tests to import this module in environments where AFL-automation
14+
# is not installed. Runtime server behavior still requires AFL-automation.
15+
if exc.name and exc.name.startswith("AFL.automation"):
16+
class Driver: # type: ignore[override]
17+
@staticmethod
18+
def unqueued(*args, **kwargs):
19+
def decorator(func):
20+
return func
21+
return decorator
22+
23+
@staticmethod
24+
def queued(*args, **kwargs):
25+
def decorator(func):
26+
return func
27+
return decorator
28+
29+
def __init__(self, *args, **kwargs):
30+
pass
31+
32+
def gather_defaults(self):
33+
return getattr(self, "defaults", {})
34+
35+
def mpl_plot_to_bytes(*args, **kwargs): # type: ignore[no-redef]
36+
raise RuntimeError("mpl_plot_to_bytes requires AFL-automation to be installed.")
37+
38+
def xarray_to_bytes(*args, **kwargs): # type: ignore[no-redef]
39+
raise RuntimeError("xarray_to_bytes requires AFL-automation to be installed.")
40+
else:
41+
raise
1142
from AFL.double_agent.Pipeline import Pipeline
1243
from AFL.double_agent.util import listify
1344

0 commit comments

Comments
 (0)