-
Notifications
You must be signed in to change notification settings - Fork 4
/
test_installer.py
166 lines (133 loc) · 4.28 KB
/
test_installer.py
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
###############################################################
# pip install .; pytest -v --capture=no -v --nocapture tests/test_installer..py::Test_installer.test_001
# pytest -v --capture=no tests/test_installer.py
# pytest -v tests/test_installer.py
###############################################################
import shutil
import os
import pytest
from cloudmesh.common.Shell import Shell
from cloudmesh.common.console import Console
from cloudmesh.common.util import banner
@pytest.mark.incremental
class Test_installer:
def test_create_dir(self):
banner("test_create_dir")
path = "tmp"
if os.path.isdir('./tmp'):
if os.path.isdir('./tmp/cloudmesh-common'):
try:
shutil.rmtree('./tmp')
except OSError:
Console.error("Failed to remove directory, exiting.")
os._exit(1)
else:
Console.error("cowardly exiting because i don't know "
"if anything valuable is in tmp")
os.exit(1)
try:
os.mkdir(path)
except OSError:
print(f"Creation of the directory {path} failed")
else:
print(f"Successfully created the directory {path}")
os.chdir(path)
assert True
def test_version(self):
banner("test_version")
cmd = "cmsi version"
result = Shell.run(cmd)
print(result)
print()
assert True
def test_info(self):
banner("test_info")
print("PWD:", os.getcwd())
cmd = "cmsi info"
result = Shell.run(cmd)
print(result)
print()
assert "We found python in" in str(result)
def test_list(self):
banner("list")
cmd = "cmsi list"
result = Shell.run(cmd)
print(result)
assert "cloudmesh-common" in result
def test_non_existing(self):
banner("test_non_existing")
print("PWD:", os.getcwd())
cmd = "cmsi git clone WRONG"
try:
result = Shell.run(cmd)
assert False
except RuntimeError:
assert True
def test_clone_community(self):
banner("test_clone_community")
print("PWD:", os.getcwd())
cmd = "cmsi git clone community"
result = Shell.run(cmd)
print(result)
assert os.path.isdir("cloudmesh-community.github.io")
def test_clone_cms(self):
banner("test_clone_cms")
print("PWD:", os.getcwd())
cmd = "cmsi git clone cms"
result = Shell.run(cmd)
print("RESULT:", result)
assert os.path.isdir("cloudmesh-cmd5")
def test_clone_ls(self):
banner("test_clone_ls")
print("PWD:", os.getcwd())
banner("ls")
cmd = "ls"
result = Shell.run(cmd)
print(result)
def test_install_cms(self):
banner("test_install_cms")
print("PWD:", os.getcwd())
cmd = "cmsi install cms"
result = Shell.run(cmd)
print("RESULT:", result)
# this is not possible to check.
# when one runs pytest,
# the python process will have to be
# rerun for the installed module to be
# available.
#
# def test_import_cms(self):
# banner("test_import_cms")
# print("PWD:", os.getcwd())
# # Try to import the module and check if it raises an ImportError
# try:
# import cloudmesh.shell
# assert True
# except ImportError:
# assert False
def test_cms_help(self):
banner("test_cms_help")
print("PWD:", os.getcwd())
cmd = "cms help"
result = Shell.run(cmd)
print(result)
assert "quit" in result
def test_cms_info(self):
banner("test_cms_info")
print("PWD:", os.getcwd())
cmd = "cms info"
result = Shell.run(cmd)
print(result)
assert "cloudmesh.common" in result
def test_cms_verion(self):
banner("test_cms_version")
print("PWD:", os.getcwd())
cmd = "cms version"
result = Shell.run(cmd)
print(result)
assert "cloudmesh.common" in result
class other:
def test_delete_dir(self):
path = "tmp"
shutil.rmtree(path)
assert True