-
Notifications
You must be signed in to change notification settings - Fork 6
/
test.py
executable file
·69 lines (58 loc) · 1.91 KB
/
test.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
from pexpect import spawn
from os import getcwd, path, makedirs
import logging
import sys
from collections import OrderedDict
logger = logging.getLogger("test")
logger.setLevel(logging.DEBUG)
ch = logging.StreamHandler()
ch.setLevel(logging.DEBUG)
logger.addHandler(ch)
cookiecutter_template_path = path.join(
path.dirname(getcwd()), "cookiecutter-sanic")
output_path = path.join(
path.dirname(cookiecutter_template_path), "output")
expect_to_arg_map = OrderedDict({
"repo_name [sanic-skeleton]: ": "sanic-test",
"app_name [sanic_skeleton]": "sanic_test",
"run [run]": "run",
"enable_swagger": "y",
"sanic_env_prefix": "SANIC_",
"sanic_port": "8000",
"sanic_host": "0.0.0.0",
"maintainer": "some random test maintainer",
"email": "[email protected]",
"github_username": "me",
"version": "0.1.0",
"Select tox_env": "2",
"Select enable_codecov": "2",
"Select enable_orm": "1",
"postgres_volume_location": "pg-data",
"Select enable_rate_limiter": "1",
"Select run_mode:": "1",
"workers": "4",
"Select enable_auto_reload": "1",
"Select enable_opentracing": "2",
})
# Setup Directory path for output
if not path.isdir(output_path):
makedirs(output_path)
cookiecutter_command = "cookiecutter {} -o {}" \
.format(cookiecutter_template_path, output_path)
logger.debug("Command being executed to Test Template Rendering: {}"
.format(cookiecutter_command))
child = spawn(cookiecutter_command)
child.logfile = sys.stdout.buffer
if child.exitstatus:
logger.error(child.stderr)
raise Exception
for expected_value, input_answer in expect_to_arg_map.items():
logger.debug("Expecting : {}".format(expected_value))
child.expect_exact([expected_value])
child.sendline(input_answer)
child.read()
child.wait()
if child.exitstatus:
logger.error("Failed to Run cookiecutter Commands")
logger.error(child.stderr)
raise Exception