1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
|
#
# Copyright 2009- ECMWF.
#
# This software is licensed under the terms of the Apache Licence version 2.0
# which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
# In applying this licence, ECMWF does not waive the privileges and immunities
# granted to it by virtue of its status as an intergovernmental organisation
# nor does it submit to any jurisdiction.
#
# This test ensures that the nodes are printed using the expected format.
from ecflow import Defs, Suite, Task, Family, Client
import ecflow_test_util as Test
import os
def test_print_defs():
defs = Defs()
with Suite("s") as s:
defs.add_suite(s)
with Family("f") as f:
s.add_family(f)
with Task("t") as t:
f.add_task(t)
t.add_variable("NAME", "VALUE")
expected = f"#{Client().version()}\nsuite s\n family f\n task t\n edit NAME 'VALUE'\n endfamily\nendsuite\n# enddef\n"
actual = defs.__str__()
assert actual == expected, "Expected:\n" + expected + "\n" + "Actual:\n" + actual
def test_print_suite():
with Suite("s") as s:
with Family("f") as f:
s.add_family(f)
with Task("t") as t:
f.add_task(t)
t.add_variable("NAME", "VALUE")
expected = "suite s\n family f\n task t\n edit NAME 'VALUE'\n endfamily\nendsuite\n"
actual = s.__str__()
assert actual == expected, "Expected:\n" + expected + "\n" + "Actual:\n" + actual
def test_print_family():
with Family("f") as f:
with Task("t") as t:
f.add_task(t)
t.add_variable("NAME", "VALUE")
expected = " family f\n task t\n edit NAME 'VALUE'\n endfamily\n"
actual = f.__str__()
assert actual == expected, "Expected:\n" + expected + "\n" + "Actual:\n" + actual
def test_print_task():
with Task("t") as t:
t.add_variable("NAME", "VALUE")
expected = " task t\n edit NAME 'VALUE'\n"
actual = t.__str__()
assert actual == expected, "Expected:\n" + expected + "\n" + "Actual:\n" + actual
if __name__ == "__main__":
Test.print_test_start(os.path.basename(__file__))
test_print_defs()
test_print_suite()
test_print_family()
test_print_task()
print("All tests pass")
|