-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest_bulker.py
More file actions
164 lines (124 loc) · 5.27 KB
/
test_bulker.py
File metadata and controls
164 lines (124 loc) · 5.27 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
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
import os
import subprocess
import pytest
import yacman
from bulker.bulker import DEFAULT_CONFIG_FILEPATH
from bulker.bulker import bulker_init, bulker_load, load_remote_registry_path, \
bulker_activate, parse_registry_paths
from bulker.bulker import mkabs
import shutil
DUMMY_CFG_FOLDER = "bulker_temp"
DUMMY_CFG_FILEPATH = os.path.join(DUMMY_CFG_FOLDER, "tmp.yaml")
DUMMY_CFG_TEMPLATES = os.path.join(DUMMY_CFG_FOLDER, "templates")
DUMMY_CFG_CRATE_SUBDIR = "crates"
def test_yacman():
bc = yacman.YAMLConfigManager.from_yaml_file(DEFAULT_CONFIG_FILEPATH)
bc
bc["bulker"]["default_crate_folder"]
yaml_str = """\
---
one: 1
2: two
"""
def test_float_idx():
data = yacman.YAMLConfigManager.from_yaml_data(yaml_str)
# We should be able to access this by string, not by int index.
assert(data['2'] == "two")
with pytest.raises(KeyError):
data[2]
del data
def test_bulker_init():
try:
shutil.rmtree(DUMMY_CFG_FOLDER)
os.mkdir(DUMMY_CFG_FOLDER)
os.mkdir(DUMMY_CFG_TEMPLATES)
# TODO: Clean up these folders
# Why do I have to pre-create these anyway? I guess to test init?
os.mkdir(os.path.join(DUMMY_CFG_TEMPLATES, "zsh_start"))
os.mkdir(os.path.join(DUMMY_CFG_TEMPLATES, "zsh_start_strict"))
except:
pass
bulker_init(DUMMY_CFG_FILEPATH, DEFAULT_CONFIG_FILEPATH, "docker")
bulker_config = yacman.YAMLConfigManager.from_yaml_file(DEFAULT_CONFIG_FILEPATH)
manifest, cratevars = load_remote_registry_path(bulker_config,
"demo",
None)
# del bulker_config
try:
shutil.rmtree(DUMMY_CFG_FOLDER)
except:
pass
def test_bulker_activate():
bulker_config = yacman.YAMLConfigManager.from_yaml_file(DEFAULT_CONFIG_FILEPATH)
def test_nonconfig_load():
try:
shutil.rmtree(DUMMY_CFG_FOLDER)
except:
pass
try:
os.mkdir(DUMMY_CFG_FOLDER)
os.mkdir(DUMMY_CFG_TEMPLATES)
# TODO: Clean up these folders
# Why do I have to pre-create these anyway? I guess to test init?
os.mkdir(os.path.join(DUMMY_CFG_TEMPLATES, "zsh_start"))
os.mkdir(os.path.join(DUMMY_CFG_TEMPLATES, "zsh_start_strict"))
except:
pass
bulker_init(DUMMY_CFG_FILEPATH, DEFAULT_CONFIG_FILEPATH, "docker")
bulker_config = yacman.YAMLConfigManager.from_yaml_file(DUMMY_CFG_FILEPATH)
# The 'load' command will write the new crate to the config file;
# we don't want it to update the template config file, so make a dummy
# filepath that we'll delete later.
# for testing, use a local crate folder
bulker_config["bulker"]["default_crate_folder"] = DUMMY_CFG_CRATE_SUBDIR
print("Bulker config: {}".format(bulker_config))
manifest, cratevars = load_remote_registry_path(bulker_config,
"demo",
None)
manifest, cratevars = load_remote_registry_path(bulker_config, "demo", None)
exe_template = mkabs(bulker_config["bulker"]["executable_template"], os.path.dirname(bulker_config.filepath))
shell_template = mkabs(bulker_config["bulker"]["shell_template"],
os.path.dirname(bulker_config.filepath))
import jinja2
with open(exe_template, 'r') as f:
contents = f.read()
exe_template_jinja = jinja2.Template(contents)
with open(shell_template, 'r') as f:
contents = f.read()
shell_template_jinja = jinja2.Template(contents)
bulker_load(manifest, cratevars, bulker_config, exe_template_jinja,
shell_template_jinja, force=True)
# bulker_config.make_readonly() # deprecated this line with yacman improvements?
cratelist = parse_registry_paths("bulker/demo")
bulker_activate(bulker_config, cratelist, echo=True, strict=False)
bulker_activate(bulker_config, cratelist, echo=True, strict=True)
# Can't really test activate if echo=False, since it replaces the current process...
print(cratelist)
# Test a reload with already-removed crate
crate_folder = os.path.join(bulker_config["bulker"]["default_crate_folder"], "bulker/demo/default")
print("removing {}".format(crate_folder))
# shutil.rmtree(crate_folder)
bulker_load(manifest, cratevars, bulker_config, exe_template_jinja,
shell_template_jinja, force=True)
del bulker_config
try:
shutil.rmtree(DUMMY_CFG_FOLDER)
except:
pass
# import inspect
# inspect.getsourcelines(yacman.yaml.SafeLoader.construct_pairs)
# Not straightforward to test the CLI directly with pytest: This works on
# local computer but not on travis; it can't find the executable
# def capture(command):
# proc = subprocess.Popen(command,
# stdout = subprocess.PIPE,
# stderr = subprocess.PIPE,
# )
# out,err = proc.communicate()
# return out, err, proc.returncode
# out, err, exitcode = capture([os.path.expandvars("$HOME/.local/bin/bulker"), "load", "demo"])
# assert exitcode == 0
# out, err, exitcode = capture([os.path.expandvars("$HOME/.local/bin/bulker"), "load", "bogusbogus"])
# assert exitcode == 1
# manifest = yacman.YAMLConfigManager(filepath="/home/ns5bc/code/bulker/demo/demo_manifest.yaml")
# bc