|
| 1 | +#!/usr/bin/env python |
| 2 | +# -*- coding: utf-8 -*- |
| 3 | +# |
| 4 | +# Copyright (c) 2024 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 |
| 16 | + |
| 17 | + |
| 18 | +class TestInstance: |
| 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_creation(self, instance : pathlib.Path) -> None: |
| 80 | + instance = Instance(instance) |
| 81 | + assert(instance.leaves() == instance.roots()) |
0 commit comments