-
-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathtest_depends_on.py
More file actions
104 lines (74 loc) · 2.7 KB
/
test_depends_on.py
File metadata and controls
104 lines (74 loc) · 2.7 KB
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#!/usr/bin/python
# Copyright (C) 2019-2022 Vanessa Sochat.
# This Source Code Form is subject to the terms of the
# Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed
# with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
from scompose.logger import bot
from scompose.project import Project
from time import sleep
import shutil
import os
here = os.path.dirname(os.path.abspath(__file__))
def test_circular_dependency(tmp_path):
depends_on = os.path.join(here, "configs", "wrong_depends_on")
for filename in os.listdir(depends_on):
source = os.path.join(depends_on, filename)
dest = os.path.join(tmp_path, filename)
print("Copying %s to %s" % (filename, dest))
shutil.copyfile(source, dest)
# Test the simple apache example
os.chdir(tmp_path)
# Check for required files
assert "singularity-compose.yml" in os.listdir()
print("Creating project...")
# Loading project validates config
project = Project()
print("Testing build")
project.build()
for image in ["first.sif", "second.sif", "third.sif"]:
assert image in os.listdir(tmp_path)
print("Testing view config")
project.view_config()
try:
print("Testing up")
project.up()
raise Exception("Up should have failed")
except SystemExit:
print("Up failed as expected")
finally:
print("Bringing down")
project.down()
def test_no_circular_dependency(tmp_path):
bot.clear() ## Clear previously logged messages
depends_on = os.path.join(here, "configs", "depends_on")
for filename in os.listdir(depends_on):
source = os.path.join(depends_on, filename)
dest = os.path.join(tmp_path, filename)
print("Copying %s to %s" % (filename, dest))
shutil.copyfile(source, dest)
# Test the simple apache example
os.chdir(tmp_path)
# Check for required files
assert "singularity-compose.yml" in os.listdir()
print("Creating project...")
# Loading project validates config
project = Project()
print("Testing build")
project.build()
for image in ["first.sif", "second.sif", "third.sif"]:
assert image in os.listdir(tmp_path)
print("Testing view config")
project.view_config()
# Test depends_on DAG order
keys = list(project.instances.keys())
assert keys == ["first1", "second1", "third1"]
print("Testing up")
project.up()
print("Waiting for instances to start")
sleep(10)
print("Bringing down")
project.down()
log = bot.get_logs()
assert log.index("Creating first") < log.index("Creating second") and log.index(
"Creating second"
) < log.index("Creating third")