Skip to content

Commit 164289b

Browse files
added tests for custom operators
1 parent cf4f107 commit 164289b

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

tests/test_python_plugins.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
CustomSpecification,
3636
PinSpecification,
3737
SpecificationProperties,
38+
Specification
3839
)
3940
import conftest
4041
from conftest import (
@@ -408,3 +409,26 @@ def test_custom_op_with_spec(server_type_remote_process, testfiles_dir):
408409
outf = op.outputs.field()
409410
expected = np.ones((3, 3), dtype=np.float64) + 4.0
410411
assert np.allclose(outf.data, expected)
412+
413+
414+
def test_custom_op_without_version(testfiles_dir):
415+
dpf.load_library(
416+
dpf.path_utilities.to_server_os(
417+
Path(testfiles_dir) / "pythonPlugins"
418+
),
419+
"py_operator_with_spec",
420+
"load_operators",
421+
)
422+
spec = Specification("custom_add_to_field")
423+
assert spec.version == "0.0.0"
424+
425+
def test_custom_op_with_version(testfiles_dir):
426+
dpf.load_library(
427+
dpf.path_utilities.to_server_os(
428+
Path(testfiles_dir) / "pythonPlugins",
429+
),
430+
"py_operator_with_spec",
431+
"load_operators"
432+
)
433+
spec = Specification("__op_with_version")
434+
assert spec.version == "2.3.1"

tests/testfiles/pythonPlugins/operator_with_spec.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,24 @@ def specification(self):
5656
def name(self):
5757
return "custom_add_to_field"
5858

59+
class OpWithVersion(CustomOperatorBase):
60+
def run(self):
61+
self.set_output("The brown fox jumps over the lazy dog.")
62+
self.set_succeeded()
63+
64+
@property
65+
def specification(self):
66+
spec = CustomSpecification()
67+
spec.description = "Outputs a string"
68+
spec.outputs = {
69+
0: PinSpecification("message", [str], "Important message")
70+
}
71+
spec.version = (2, 3, 1)
72+
return spec
73+
@property
74+
def name(self):
75+
return "__op_with_version"
5976

6077
def load_operators(*args):
6178
record_operator(AddFloatToFieldData, *args)
79+
record_operator(OpWithVersion, *args)

0 commit comments

Comments
 (0)