Skip to content

Commit 69723a6

Browse files
committed
Merge branch 'main' into flowcept_improvements
2 parents b521001 + 68d7ce0 commit 69723a6

4 files changed

Lines changed: 142 additions & 4 deletions

File tree

tests/unit/test_utils.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
#
4+
# Copyright (c) 2025 The WfCommons Team.
5+
#
6+
# This program is free software: you can redistribute it and/or modify
7+
# it under the terms of the GNU General Public License as published by
8+
# the Free Software Foundation, either version 3 of the License, or
9+
# (at your option) any later version.
10+
11+
import json
12+
import pathlib
13+
import pytest
14+
import wfcommons.utils
15+
16+
from typing import Dict, List, Tuple
17+
18+
19+
class TestUtils:
20+
21+
@pytest.mark.unit
22+
@pytest.mark.parametrize(
23+
"data,distribution",
24+
[
25+
pytest.param([1, 2, 3], ("rdist", (1.5504806356651624, 0.0013236200991527764, 0.0013236200991527767))),
26+
pytest.param([1, 1, 1], ("pareto", (2.25803497307119, -7.535551383120264e-19, 4.806600020282434e-19))),
27+
],
28+
)
29+
def test_best_fit_distribution(self, data: List[float], distribution: Tuple) -> None:
30+
assert(wfcommons.utils.best_fit_distribution(data) == distribution)
31+
32+
@pytest.mark.unit
33+
@pytest.mark.parametrize(
34+
"distribution,min_value,max_value",
35+
[
36+
pytest.param(None, 10, 100),
37+
pytest.param({"name": "norm", "params": [0.08688656476267097, 0.2572832376513094]}, 10, 100),
38+
],
39+
)
40+
def test_generate_rvs(self, distribution: Dict, min_value: float, max_value: float) -> None:
41+
assert(min_value <= wfcommons.utils.generate_rvs(distribution, min_value, max_value) <= max_value )
42+
43+
@pytest.mark.unit
44+
@pytest.mark.parametrize(
45+
"n,r,combinations",
46+
[
47+
pytest.param(2, 2, 1),
48+
pytest.param(10, 2, 45),
49+
pytest.param(10, 3, 120),
50+
],
51+
)
52+
def test_ncr(self, n: int, r: int, combinations: int) -> None:
53+
assert(wfcommons.utils.ncr(n, r) == combinations)
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
#
4+
# Copyright (c) 2025 The WfCommons Team.
5+
#
6+
# This program is free software: you can redistribute it and/or modify
7+
# it under the terms of the GNU General Public License as published by
8+
# the Free Software Foundation, either version 3 of the License, or
9+
# (at your option) any later version.
10+
11+
import json
12+
import pathlib
13+
import pytest
14+
15+
from wfcommons.wfinstances import Instance, InstanceAnalyzer
16+
17+
18+
class TestInstanceAnalyzer:
19+
20+
@pytest.fixture
21+
def instance(self) -> pathlib.Path:
22+
instance = {
23+
"name": "workflow_test",
24+
"description": "Instance generate for WfCommons Test",
25+
"createdAt": "2020-12-30T02:19:01.238077",
26+
"schemaVersion": "1.5",
27+
"author": {
28+
"name": "wfcommons",
29+
"email": "support@wfcommons.org"
30+
},
31+
"workflow": {
32+
"specification": {
33+
"tasks": [
34+
{
35+
"name": "task_01",
36+
"id": "task_01",
37+
"children": ["task_02", "task_03"],
38+
"inputFiles": ["input_01.txt", "input_02.txt"],
39+
"outputFiles": ["output_01.txt"],
40+
"parents": []
41+
}
42+
],
43+
"files": [
44+
{"id": "input_01.txt", "sizeInBytes": 10}, {"id": "input_02.txt", "sizeInBytes": 20},
45+
{"id": "output_01.txt", "sizeInBytes": 15}
46+
]
47+
},
48+
"execution": {
49+
"makespanInSeconds": 111.5,
50+
"executedAt": "2024-11-30T03:25:55+00:00",
51+
"tasks": [
52+
{
53+
"id": "task_01",
54+
"runtimeInSeconds": 0.052203,
55+
"command": {
56+
"program": "program_1",
57+
"arguments": ["a", "b"]
58+
},
59+
"coreCount": 1,
60+
"avgCPU": 90.123,
61+
"readBytes": 150,
62+
"writtenBytes": 200,
63+
"memoryInBytes": 300,
64+
"machines": ["worker-1"]
65+
}
66+
],
67+
"machines": [
68+
{"nodeName": "worker-1", "cpu": {"coreCount": 24}}
69+
]
70+
}
71+
},
72+
"runtimeSystem": {"name": "wfcommons", "version": "1.0", "url": "https://wfcommons.org"}
73+
}
74+
instance_path = pathlib.Path("/tmp/wfcommons_test_workflow.json")
75+
instance_path.write_text(json.dumps(instance))
76+
return instance_path
77+
78+
@pytest.mark.unit
79+
def test_instance_analyzer_summary(self, instance : pathlib.Path) -> None:
80+
instance = Instance(instance)
81+
analyzer = InstanceAnalyzer()
82+
analyzer.append_instance(instance)
83+
workflow_tasks = ['task_01']
84+
summary = analyzer.build_summary(workflow_tasks, include_raw_data=False)
85+
assert(summary == {'task_01': {'runtime': {'min': 0.052203, 'max': 0.052203, 'distribution': {'name': 'dweibull', 'params': [0.19451622991431783, 4.155260197271249e-34, 1.161132255170155]}}, 'input': {'.txt': {'distribution': {'name': 'rdist', 'params': [1.5504806356651624, 0.0013236200991527764, 0.0013236200991527767]}, 'min': 10, 'max': 20}}, 'output': {'.txt': {'distribution': None, 'min': 15, 'max': 15}}}})

wfcommons/wfbench/translator/cwl.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ def _parse_steps(self) -> None:
132132

133133
code = [
134134
f" {task.task_id}:",
135-
" run: clt/bash.cwl",
135+
" run: clt/shell.cwl",
136136
" in:",
137137
]
138138

@@ -224,7 +224,7 @@ def _write_cwl_files(self, output_folder: pathlib.Path) -> None:
224224
clt_folder.mkdir(exist_ok=True)
225225
shutil.copy(this_dir.joinpath("templates/cwl_templates/wfbench.cwl"), clt_folder)
226226
shutil.copy(this_dir.joinpath("templates/cwl_templates/folder.cwl"), clt_folder)
227-
shutil.copy(this_dir.joinpath("templates/cwl_templates/bash.cwl"), clt_folder)
227+
shutil.copy(this_dir.joinpath("templates/cwl_templates/shell.cwl"), clt_folder)
228228

229229
with open(cwl_folder.joinpath("main.cwl"), "w", encoding="utf-8") as f:
230230
f.write("\n".join(self.cwl_script))

wfcommons/wfbench/translator/templates/cwl_templates/shell.cwl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ class: CommandLineTool
33
requirements:
44
InlineJavascriptRequirement: {}
55
ShellCommandRequirement: {}
6-
stdout: $("logs/" + inputs.step_name + ".out")
7-
stderr: $("logs/" + inputs.step_name + ".err")
6+
stdout: $(inputs.step_name + ".out")
7+
stderr: $(inputs.step_name + ".err")
88

99
arguments:
1010
- position: 1

0 commit comments

Comments
 (0)