/
environment_test.py
103 lines (57 loc) 路 3.09 KB
/
environment_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
95
96
97
98
99
100
101
102
103
import os
from cibuildwheel.environment import parse_environment
def test_basic_parsing():
environment_recipe = parse_environment("VAR=1 VBR=2")
environment_dict = environment_recipe.as_dictionary(prev_environment={})
assert environment_dict == {"VAR": "1", "VBR": "2"}
def test_quotes():
environment_recipe = parse_environment("A=1 VAR=\"1 NOT_A_VAR=2\" VBR='vbr'")
environment_dict = environment_recipe.as_dictionary(prev_environment={})
assert environment_dict == {"A": "1", "VAR": "1 NOT_A_VAR=2", "VBR": "vbr"}
def test_inheritance():
environment_recipe = parse_environment("PATH=$PATH:/usr/local/bin")
environment_dict = environment_recipe.as_dictionary(prev_environment={"PATH": "/usr/bin"})
assert environment_dict == {"PATH": "/usr/bin:/usr/local/bin"}
def test_shell_eval():
environment_recipe = parse_environment('VAR="$(echo "a test" string)"')
env_copy = os.environ.copy()
env_copy.pop("VAR", None)
environment_dict = environment_recipe.as_dictionary(prev_environment=env_copy)
assert environment_dict["VAR"] == "a test string"
def test_shell_eval_and_env():
environment_recipe = parse_environment('VAR="$(echo "$PREV_VAR" string)"')
environment_dict = environment_recipe.as_dictionary(prev_environment={"PREV_VAR": "1 2 3"})
assert environment_dict == {"PREV_VAR": "1 2 3", "VAR": "1 2 3 string"}
def test_empty_var():
environment_recipe = parse_environment("CFLAGS=")
environment_dict = environment_recipe.as_dictionary(prev_environment={"CFLAGS": "-Wall"})
assert environment_dict == {"CFLAGS": ""}
def test_no_vars():
environment_recipe = parse_environment("")
environment_dict = environment_recipe.as_dictionary(prev_environment={})
assert environment_dict == {}
def test_no_vars_pass_through():
environment_recipe = parse_environment("")
environment_dict = environment_recipe.as_dictionary(
prev_environment={"CIBUILDWHEEL": "awesome"}
)
assert environment_dict == {"CIBUILDWHEEL": "awesome"}
def test_operators_inside_eval():
environment_recipe = parse_environment('SOMETHING="$(echo a; echo b; echo c)"')
# pass the existing process env so PATH is available
environment_dict = environment_recipe.as_dictionary(os.environ.copy())
assert environment_dict.get("SOMETHING") == "a\nb\nc"
def test_substitution_with_backslash():
environment_recipe = parse_environment('PATH2="somewhere_else;$PATH1"')
# pass the existing process env so PATH is available
environment_dict = environment_recipe.as_dictionary(prev_environment={"PATH1": "c:\\folder\\"})
assert environment_dict.get("PATH2") == "somewhere_else;c:\\folder\\"
def test_awkwardly_quoted_variable():
environment_recipe = parse_environment(
'VAR2=something"like this""$VAR1"$VAR1$(echo "there is more")"$(echo "and more!")"'
)
# pass the existing process env so PATH is available
environment_dict = environment_recipe.as_dictionary({"VAR1": "but wait"})
assert (
environment_dict.get("VAR2") == "somethinglike thisbut waitbut waitthere is moreand more!"
)