-
Notifications
You must be signed in to change notification settings - Fork 4
/
test.py
94 lines (74 loc) · 2.09 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
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
from __future__ import print_function
import argparse
import os
import re
import sys
def parse_arguments(arguments):
parser = argparse.ArgumentParser(
description="Test the python-info-action output",
)
parser.add_argument(
"--path",
required=True,
help="The path to the action's output file.",
)
parser.add_argument(
"--package",
required=False,
nargs=2,
action='append',
default=[],
help="Argument and version pair. You can pass multiple times.",
)
parser.add_argument(
"--sys-prefix",
required=False,
default=sys.prefix,
help=(
"The sys.prefix to check for in case the tests are run in"
" an env other than the action."
),
)
return parser.parse_args(args=arguments)
def main(raw_arguments):
arguments = parse_arguments(arguments=raw_arguments)
with open(arguments.path) as f:
output = f.read()
secret_text = "neverseethis"
assert secret_text not in output
assert secret_text == os.environ["A_SECRET"]
relative_path = os.path.relpath(arguments.path, os.getcwd())
assert re.search(
"^'ACTION_FILE_PATH' +: '{}'$".format(re.escape(relative_path)),
output,
re.MULTILINE,
)
assert re.search(
"^sys.prefix +: {}$".format(re.escape(arguments.sys_prefix)),
output,
re.MULTILINE,
)
assert re.search(
"^'platstdlib' +: ",
output,
re.MULTILINE,
)
assert re.search(
"^'platbase' +: ",
output,
re.MULTILINE,
)
arguments.package.append(("pip", None))
for name, version in arguments.package:
if version is None:
re_version = ".*"
else:
re_version = re.escape(version)
print("checking for: {}, {}".format(name, version))
assert re.search(
"^{}=={}$".format(re.escape(name), re_version),
output,
re.MULTILINE,
)
if __name__ == "__main__":
sys.exit(main(raw_arguments=sys.argv[1:]))