Skip to content

Commit c110953

Browse files
authored
Merge pull request #7958 from ilanschnell/add-yaml-options
Add ability to run pip with options for yaml tests
2 parents 327a315 + 2b883d5 commit c110953

File tree

8 files changed

+83
-67
lines changed

8 files changed

+83
-67
lines changed

tests/functional/test_yaml.py

+33-36
Original file line numberDiff line numberDiff line change
@@ -92,39 +92,43 @@ def stripping_split(my_str, splitwith, count=None):
9292
return retval
9393

9494

95-
def handle_install_request(script, requirement):
95+
def handle_request(script, action, requirement, options):
9696
assert isinstance(requirement, str), (
9797
"Need install requirement to be a string only"
9898
)
99-
result = script.pip(
100-
"install",
101-
"--no-index", "--find-links", path_to_url(script.scratch_path),
102-
requirement, "--verbose",
103-
allow_stderr_error=True,
104-
allow_stderr_warning=True,
105-
)
99+
if action == 'install':
100+
args = ['install', "--no-index", "--find-links",
101+
path_to_url(script.scratch_path)]
102+
elif action == 'uninstall':
103+
args = ['uninstall', '--yes']
104+
else:
105+
raise "Did not excpet action: {!r}".format(action)
106+
args.append(requirement)
107+
args.extend(options)
108+
args.append("--verbose")
109+
110+
result = script.pip(*args,
111+
allow_stderr_error=True,
112+
allow_stderr_warning=True)
106113

107114
retval = {
108115
"_result_object": result,
109116
}
110117
if result.returncode == 0:
111118
# Check which packages got installed
112-
retval["install"] = []
119+
retval["state"] = []
113120

114-
for path in result.files_created:
121+
for path in os.listdir(script.site_packages_path):
115122
if path.endswith(".dist-info"):
116123
name, version = (
117124
os.path.basename(path)[:-len(".dist-info")]
118125
).rsplit("-", 1)
119126

120127
# TODO: information about extras.
121128

122-
retval["install"].append(" ".join((name, version)))
123-
124-
retval["install"].sort()
129+
retval["state"].append(" ".join((name, version)))
125130

126-
# TODO: Support checking uninstallations
127-
# retval["uninstall"] = []
131+
retval["state"].sort()
128132

129133
elif "conflicting" in result.stderr.lower():
130134
retval["conflicting"] = []
@@ -151,10 +155,10 @@ def handle_install_request(script, requirement):
151155
def test_yaml_based(script, case):
152156
available = case.get("available", [])
153157
requests = case.get("request", [])
154-
transaction = case.get("transaction", [])
158+
responses = case.get("response", [])
155159

156-
assert len(requests) == len(transaction), (
157-
"Expected requests and transaction counts to be same"
160+
assert len(requests) == len(responses), (
161+
"Expected requests and responses counts to be same"
158162
)
159163

160164
# Create a custom index of all the packages that are supposed to be
@@ -168,26 +172,19 @@ def test_yaml_based(script, case):
168172

169173
create_basic_wheel_for_package(script, **package)
170174

171-
available_actions = {
172-
"install": handle_install_request
173-
}
174-
175175
# use scratch path for index
176-
for request, expected in zip(requests, transaction):
177-
# The name of the key is what action has to be taken
178-
assert len(request.keys()) == 1, "Expected only one action"
176+
for request, response in zip(requests, responses):
179177

180-
# Get the only key
181-
action = list(request.keys())[0]
182-
183-
assert action in available_actions.keys(), (
184-
"Unsupported action {!r}".format(action)
185-
)
178+
for action in 'install', 'uninstall':
179+
if action in request:
180+
break
181+
else:
182+
raise "Unsupported request {!r}".format(request)
186183

187184
# Perform the requested action
188-
effect = available_actions[action](script, request[action])
189-
190-
result = effect["_result_object"]
191-
del effect["_result_object"]
185+
effect = handle_request(script, action,
186+
request[action],
187+
request.get('options', '').split())
192188

193-
assert effect == expected, str(result)
189+
assert effect['state'] == (response['state'] or []), \
190+
str(effect["_result_object"])

tests/yaml/install/circular.yml

+8-8
Original file line numberDiff line numberDiff line change
@@ -10,35 +10,35 @@ cases:
1010
-
1111
request:
1212
- install: A
13-
transaction:
14-
- install:
13+
response:
14+
- state:
1515
- A 1.0.0
1616
- B 1.0.0
1717
- C 1.0.0
1818
- D 1.0.0
1919
-
2020
request:
2121
- install: B
22-
transaction:
23-
- install:
22+
response:
23+
- state:
2424
- A 1.0.0
2525
- B 1.0.0
2626
- C 1.0.0
2727
- D 1.0.0
2828
-
2929
request:
3030
- install: C
31-
transaction:
32-
- install:
31+
response:
32+
- state:
3333
- A 1.0.0
3434
- B 1.0.0
3535
- C 1.0.0
3636
- D 1.0.0
3737
-
3838
request:
3939
- install: D
40-
transaction:
41-
- install:
40+
response:
41+
- state:
4242
- A 1.0.0
4343
- B 1.0.0
4444
- C 1.0.0

tests/yaml/install/conflicting_diamond.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ cases:
88
- D 2.0.0
99
request:
1010
- install: A
11-
transaction:
11+
response:
1212
- conflicting:
1313
- required_by: [A 1.0.0, B 1.0.0]
1414
selector: D == 1.0.0

tests/yaml/install/conflicting_triangle.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ cases:
88
request:
99
- install: A
1010
- install: B
11-
transaction:
12-
- install:
11+
response:
12+
- state:
1313
- A 1.0.0
1414
- C 1.0.0
1515
- conflicting:

tests/yaml/install/extras.yml

+6-6
Original file line numberDiff line numberDiff line change
@@ -15,24 +15,24 @@ cases:
1515
-
1616
request:
1717
- install: B
18-
transaction:
19-
- install:
18+
response:
19+
- state:
2020
- B 1.0.0
2121
- D 1.0.0
2222
- E 1.0.0
2323
-
2424
request:
2525
- install: C
26-
transaction:
27-
- install:
26+
response:
27+
- state:
2828
- C 1.0.0
2929
- D 1.0.0
3030
- F 1.0.0
3131
-
3232
request:
3333
- install: A
34-
transaction:
35-
- install:
34+
response:
35+
- state:
3636
- A 1.0.0
3737
- B 1.0.0
3838
- C 1.0.0

tests/yaml/install/non_pinned.yml

+4-4
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@ cases:
1111
-
1212
request:
1313
- install: A >= 2.0.0
14-
transaction:
15-
- install:
14+
response:
15+
- state:
1616
- A 2.0.0
1717
- B 2.1.0
1818
-
1919
request:
2020
- install: A < 2.0.0
21-
transaction:
22-
- install:
21+
response:
22+
- state:
2323
- A 1.0.0
2424
- B 1.0.0

tests/yaml/install/pinned.yml

+6-6
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,21 @@ cases:
99
-
1010
request:
1111
- install: B
12-
transaction:
13-
- install:
12+
response:
13+
- state:
1414
- A 2.0.0
1515
- B 2.0.0
1616
-
1717
request:
1818
- install: B == 2.0.0
19-
transaction:
20-
- install:
19+
response:
20+
- state:
2121
- A 2.0.0
2222
- B 2.0.0
2323
-
2424
request:
2525
- install: B == 1.0.0
26-
transaction:
27-
- install:
26+
response:
27+
- state:
2828
- A 1.0.0
2929
- B 1.0.0

tests/yaml/install/simple.yml

+23-4
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,32 @@ cases:
99
-
1010
request:
1111
- install: simple
12-
transaction:
13-
- install:
12+
- uninstall: simple
13+
response:
14+
- state:
15+
- simple 0.2.0
16+
- state: null
17+
-
18+
request:
19+
- install: simple
20+
- install: dep
21+
response:
22+
- state:
23+
- simple 0.2.0
24+
- state:
25+
- dep 0.1.0
1426
- simple 0.2.0
1527
-
1628
request:
1729
- install: base
18-
transaction:
19-
- install:
30+
response:
31+
- state:
2032
- base 0.1.0
2133
- dep 0.1.0
34+
-
35+
request:
36+
- install: base
37+
options: --no-deps
38+
response:
39+
- state:
40+
- base 0.1.0

0 commit comments

Comments
 (0)