Add All Folders
This commit is contained in:
BIN
Binary file not shown.
BIN
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,43 @@
|
||||
from radiuma_api.io_port import (
|
||||
CompositeType,
|
||||
ImageType,
|
||||
TextType,
|
||||
TableType,
|
||||
CompatibilityException
|
||||
)
|
||||
|
||||
def test_composite_type_success():
|
||||
t1 = CompositeType({
|
||||
"img": ImageType(),
|
||||
"meta": TextType(language="en")
|
||||
})
|
||||
|
||||
t2 = CompositeType({
|
||||
"img": ImageType(),
|
||||
"meta": TextType(language="en")
|
||||
})
|
||||
|
||||
# Must succeed
|
||||
t1.can_connect_to(t2)
|
||||
|
||||
|
||||
def test_composite_type_key_mismatch():
|
||||
t1 = CompositeType({"img": ImageType()})
|
||||
t2 = CompositeType({"image": ImageType()})
|
||||
|
||||
try:
|
||||
t1.can_connect_to(t2)
|
||||
assert False, "Expected CompositeType key mismatch"
|
||||
except CompatibilityException:
|
||||
assert True
|
||||
|
||||
|
||||
def test_composite_type_internal_type_mismatch():
|
||||
t1 = CompositeType({"img": ImageType(modality="nifti")})
|
||||
t2 = CompositeType({"img": ImageType(modality="dicom")})
|
||||
|
||||
try:
|
||||
t1.can_connect_to(t2)
|
||||
assert False, "Expected internal DType mismatch"
|
||||
except CompatibilityException:
|
||||
assert True
|
||||
@@ -0,0 +1,17 @@
|
||||
from radiuma_api.execution_context import ExecutionContext
|
||||
from radiuma_api.io_port import OutPort, InPort, ImageType
|
||||
from radiuma_api.asset import Asset
|
||||
# Codes Go Below:
|
||||
|
||||
|
||||
def test_context_put_get():
|
||||
ctx = ExecutionContext()
|
||||
outp = OutPort("o", ImageType())
|
||||
inp = InPort("i", ImageType())
|
||||
|
||||
outp.connect(inp)
|
||||
|
||||
asset = Asset(["img1"], "images")
|
||||
ctx.put(outp, asset)
|
||||
|
||||
assert ctx.get(inp).data == ["img1"]
|
||||
@@ -0,0 +1,39 @@
|
||||
from radiuma_api.io_port import InPort, OutPort, ImageType, TextType, CompatibilityException
|
||||
# Codes Go Below:
|
||||
|
||||
|
||||
def test_compatible_ports():
|
||||
"""Ports with the same DType must connect successfully."""
|
||||
outp = OutPort("o", ImageType())
|
||||
inp = InPort("i", ImageType())
|
||||
|
||||
outp.connect(inp)
|
||||
|
||||
assert inp.connected_output == outp
|
||||
|
||||
|
||||
def test_incompatible_ports():
|
||||
"""Connecting mismatched DTypes must raise CompatibilityException."""
|
||||
outp = OutPort("o", ImageType())
|
||||
inp = InPort("i", TextType())
|
||||
|
||||
try:
|
||||
outp.connect(inp)
|
||||
assert False, "Expected CompatibilityException"
|
||||
except CompatibilityException:
|
||||
assert True
|
||||
|
||||
|
||||
def test_outport_single_connection_limit():
|
||||
"""OutPort must not allow more than one connection."""
|
||||
outp = OutPort("o", ImageType())
|
||||
inp1 = InPort("i1", ImageType())
|
||||
inp2 = InPort("i2", ImageType())
|
||||
|
||||
outp.connect(inp1)
|
||||
|
||||
try:
|
||||
outp.connect(inp2)
|
||||
assert False, "Expected OutPort max connections error"
|
||||
except CompatibilityException:
|
||||
assert True
|
||||
@@ -0,0 +1,43 @@
|
||||
from radiuma_api.scheduler import Scheduler
|
||||
from radiuma_api.workflow import Workflow
|
||||
from radiuma_api.module import Module
|
||||
from radiuma_api.io_port import InPort, OutPort, ImageType
|
||||
from radiuma_api.execution_context import ExecutionContext
|
||||
from radiuma_api.task import Status
|
||||
# Codes Go below:
|
||||
|
||||
|
||||
class Reader(Module):
|
||||
def __init__(self):
|
||||
super().__init__("Reader")
|
||||
self._add_output_port(OutPort("images", ImageType()))
|
||||
|
||||
def run(self, context):
|
||||
context.put(self.outputs[0], "DATA")
|
||||
self._set_status(Status.COMPLETED)
|
||||
|
||||
class Extractor(Module):
|
||||
def __init__(self):
|
||||
super().__init__("Extractor")
|
||||
self._add_input_port(InPort("images", ImageType()))
|
||||
|
||||
def run(self, context):
|
||||
assert context.get(self.inputs[0]) == "DATA"
|
||||
self._set_status(Status.COMPLETED)
|
||||
|
||||
def test_scheduler_runs_in_order():
|
||||
ctx = ExecutionContext()
|
||||
wf = Workflow("WF")
|
||||
|
||||
r = Reader()
|
||||
e = Extractor()
|
||||
|
||||
r.outputs[0].connect(e.inputs[0])
|
||||
|
||||
wf.add_child(r)
|
||||
wf.add_child(e)
|
||||
|
||||
wf.run(ctx)
|
||||
|
||||
assert r.status == Status.COMPLETED
|
||||
assert e.status == Status.COMPLETED
|
||||
@@ -0,0 +1,24 @@
|
||||
from radiuma_api.task import Status
|
||||
from radiuma_api.module import Module
|
||||
from radiuma_api.execution_context import ExecutionContext
|
||||
from radiuma_api.io_port import OutPort, ImageType
|
||||
# Codes Go below:
|
||||
|
||||
|
||||
class Dummy(Module):
|
||||
def __init__(self):
|
||||
super().__init__("Dummy")
|
||||
self._add_output_port(OutPort("o", ImageType()))
|
||||
|
||||
def run(self, context):
|
||||
self._set_status(Status.RUNNING)
|
||||
context.put(self.outputs[0], None)
|
||||
self._set_status(Status.COMPLETED)
|
||||
|
||||
def test_task_lifecycle():
|
||||
ctx = ExecutionContext()
|
||||
t = Dummy()
|
||||
|
||||
assert t.status == Status.PENDING
|
||||
t.run(ctx)
|
||||
assert t.status == Status.COMPLETED
|
||||
@@ -0,0 +1,57 @@
|
||||
from radiuma_api.workflow import Workflow
|
||||
from radiuma_api.execution_context import ExecutionContext
|
||||
from radiuma_api.io_port import InPort, OutPort, ImageType, TextType
|
||||
from radiuma_api.module import Module
|
||||
from radiuma_api.task import Status
|
||||
from radiuma_api.asset import Asset
|
||||
# Codes Go below:
|
||||
|
||||
|
||||
class Reader(Module):
|
||||
def __init__(self):
|
||||
super().__init__("Reader")
|
||||
self._add_output_port(OutPort("images", ImageType()))
|
||||
|
||||
def run(self, context):
|
||||
context.put(self.outputs[0], Asset(["img1"], "images"))
|
||||
self._set_status(Status.COMPLETED)
|
||||
|
||||
class Extractor(Module):
|
||||
def __init__(self):
|
||||
super().__init__("Extractor")
|
||||
self._add_input_port(InPort("images", ImageType()))
|
||||
self._add_output_port(OutPort("features", TextType()))
|
||||
|
||||
def run(self, context):
|
||||
imgs = context.get(self.inputs[0]).data
|
||||
context.put(self.outputs[0], Asset([{"img": imgs[0]}], "features"))
|
||||
self._set_status(Status.COMPLETED)
|
||||
|
||||
class Writer(Module):
|
||||
def __init__(self):
|
||||
super().__init__("Writer")
|
||||
self._add_input_port(InPort("features", TextType()))
|
||||
|
||||
def run(self, context):
|
||||
feats = context.get(self.inputs[0]).data
|
||||
assert feats[0]["img"] == "img1"
|
||||
self._set_status(Status.COMPLETED)
|
||||
|
||||
def test_end_to_end():
|
||||
ctx = ExecutionContext()
|
||||
wf = Workflow("WF")
|
||||
|
||||
r = Reader()
|
||||
e = Extractor()
|
||||
w = Writer()
|
||||
|
||||
r.outputs[0].connect(e.inputs[0])
|
||||
e.outputs[0].connect(w.inputs[0])
|
||||
|
||||
wf.add_child(r)
|
||||
wf.add_child(e)
|
||||
wf.add_child(w)
|
||||
|
||||
wf.run(ctx)
|
||||
|
||||
assert w.status == Status.COMPLETED
|
||||
Reference in New Issue
Block a user