Skip to content
This repository was archived by the owner on Aug 25, 2024. It is now read-only.

Commit ac13056

Browse files
John Andersenpdxjohnny
authored andcommitted
test: service: develop: Run single
Signed-off-by: John Andersen <[email protected]>
1 parent 2d4ff40 commit ac13056

File tree

2 files changed

+41
-28
lines changed

2 files changed

+41
-28
lines changed

dffml/service/dev.py

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -208,27 +208,24 @@ async def run_op(self, name, opimp):
208208
except MissingConfig as error:
209209
error.args = (f"{opimp.op.inputs}: {error.args[0]}",)
210210
raise error
211-
# Run the operation in an orchestrator
212-
async with MemoryOrchestrator.basic_config(
213-
opimp.imp, GetSingle.imp
214-
) as orchestrator:
215-
async with orchestrator() as octx:
216-
# TODO Assign a sha384 string as the random string context
217-
await octx.ictx.sadd(
218-
str(uuid.uuid4()),
219-
Input(
220-
value=[
221-
definition.name
222-
for definition in opimp.op.outputs.values()
223-
],
224-
definition=GetSingle.op.inputs["spec"],
225-
),
226-
*inputs,
227-
)
228-
async for ctx, results in octx.run_operations():
229-
# TODO There is probably an issue if multiple outputs have
230-
# the same data type that only one will be shown
231-
return results[GetSingle.op.name]
211+
212+
# Run the operation in the memory orchestrator
213+
async with MemoryOrchestrator.withconfig({}) as orchestrator:
214+
# Orchestrate the running of these operations
215+
async with orchestrator(DataFlow.auto(GetSingle, opimp)) as octx:
216+
async for ctx, results in octx.run(
217+
[
218+
Input(
219+
value=[
220+
definition.name
221+
for definition in opimp.op.outputs.values()
222+
],
223+
definition=GetSingle.op.inputs["spec"],
224+
),
225+
*inputs,
226+
]
227+
):
228+
return results
232229

233230

234231
class ListEntrypoints(CMD):

tests/test_integration_cli.py

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,17 +51,20 @@ class IntegrationCLITestCase(AsyncTestCase):
5151

5252
async def setUp(self):
5353
super().setUp()
54-
if not all(map(is_develop, self.REQUIRED_PLUGINS)):
55-
self.skipTest(
56-
f"Required plugins: {', '.join(self.REQUIRED_PLUGINS)} must be installed in development mode"
57-
)
54+
self.required_plugins(*self.REQUIRED_PLUGINS)
5855
self.stdout = io.StringIO()
5956
self._stack = contextlib.ExitStack().__enter__()
6057

6158
async def tearDown(self):
6259
super().tearDown()
6360
self._stack.__exit__(None, None, None)
6461

62+
def required_plugins(self, *args):
63+
if not all(map(is_develop, args)):
64+
self.skipTest(
65+
f"Required plugins: {', '.join(args)} must be installed in development mode"
66+
)
67+
6568
def mktempfile(self):
6669
return self._stack.enter_context(non_existant_tempfile())
6770

@@ -136,17 +139,30 @@ async def test_memory_to_csv(self):
136139

137140

138141
class TestDevelop(IntegrationCLITestCase):
139-
140-
REQUIRED_PLUGINS = ["shouldi"]
141-
142142
async def test_export(self):
143+
self.required_plugins("shouldi")
143144
stdout = io.StringIO()
144145
# Use shouldi's dataflow for tests
145146
with relative_chdir("..", "examples", "shouldi"):
146147
with unittest.mock.patch("sys.stdout.buffer.write") as write:
147148
await Develop.cli("export", "shouldi.cli:DATAFLOW")
148149
DataFlow._fromdict(**json.loads(write.call_args[0][0]))
149150

151+
async def test_run(self):
152+
self.required_plugins("shouldi", "dffml-model-scratch")
153+
results = await Develop.cli(
154+
"run",
155+
"-log",
156+
"debug",
157+
"shouldi.bandit:run_bandit",
158+
"-pkg",
159+
str(relative_path("..", "model", "scratch")),
160+
)
161+
self.assertIn("bandit_output", results)
162+
self.assertIn(
163+
"CONFIDENCE.HIGH_AND_SEVERITY.HIGH", results["bandit_output"]
164+
)
165+
150166

151167
class TestDataFlow(IntegrationCLITestCase):
152168

0 commit comments

Comments
 (0)