@@ -92,39 +92,43 @@ def stripping_split(my_str, splitwith, count=None):
92
92
return retval
93
93
94
94
95
- def handle_install_request (script , requirement ):
95
+ def handle_request (script , action , requirement , options ):
96
96
assert isinstance (requirement , str ), (
97
97
"Need install requirement to be a string only"
98
98
)
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 )
106
113
107
114
retval = {
108
115
"_result_object" : result ,
109
116
}
110
117
if result .returncode == 0 :
111
118
# Check which packages got installed
112
- retval ["install " ] = []
119
+ retval ["state " ] = []
113
120
114
- for path in result . files_created :
121
+ for path in os . listdir ( script . site_packages_path ) :
115
122
if path .endswith (".dist-info" ):
116
123
name , version = (
117
124
os .path .basename (path )[:- len (".dist-info" )]
118
125
).rsplit ("-" , 1 )
119
126
120
127
# TODO: information about extras.
121
128
122
- retval ["install" ].append (" " .join ((name , version )))
123
-
124
- retval ["install" ].sort ()
129
+ retval ["state" ].append (" " .join ((name , version )))
125
130
126
- # TODO: Support checking uninstallations
127
- # retval["uninstall"] = []
131
+ retval ["state" ].sort ()
128
132
129
133
elif "conflicting" in result .stderr .lower ():
130
134
retval ["conflicting" ] = []
@@ -151,10 +155,10 @@ def handle_install_request(script, requirement):
151
155
def test_yaml_based (script , case ):
152
156
available = case .get ("available" , [])
153
157
requests = case .get ("request" , [])
154
- transaction = case .get ("transaction " , [])
158
+ responses = case .get ("response " , [])
155
159
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"
158
162
)
159
163
160
164
# Create a custom index of all the packages that are supposed to be
@@ -168,26 +172,19 @@ def test_yaml_based(script, case):
168
172
169
173
create_basic_wheel_for_package (script , ** package )
170
174
171
- available_actions = {
172
- "install" : handle_install_request
173
- }
174
-
175
175
# 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 ):
179
177
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 )
186
183
187
184
# 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 ())
192
188
193
- assert effect == expected , str (result )
189
+ assert effect ['state' ] == (response ['state' ] or []), \
190
+ str (effect ["_result_object" ])
0 commit comments