99import ensurepip
1010import ensurepip ._uninstall
1111
12- # pip currently requires ssl support, so we ensure we handle
13- # it being missing (http://bugs.python.org/issue19744)
14- ensurepip_no_ssl = test .support .import_fresh_module ("ensurepip" ,
15- blocked = ["ssl" ])
16- try :
17- import ssl
18- except ImportError :
19- def requires_usable_pip (f ):
20- deco = unittest .skip (ensurepip ._MISSING_SSL_MESSAGE )
21- return deco (f )
22- else :
23- def requires_usable_pip (f ):
24- return f
2512
2613class TestEnsurePipVersion (unittest .TestCase ):
2714
@@ -47,7 +34,6 @@ def setUp(self):
4734
4835class TestBootstrap (EnsurepipMixin , unittest .TestCase ):
4936
50- @requires_usable_pip
5137 def test_basic_bootstrapping (self ):
5238 ensurepip .bootstrap ()
5339
@@ -62,7 +48,6 @@ def test_basic_bootstrapping(self):
6248 additional_paths = self .run_pip .call_args [0 ][1 ]
6349 self .assertEqual (len (additional_paths ), 2 )
6450
65- @requires_usable_pip
6651 def test_bootstrapping_with_root (self ):
6752 ensurepip .bootstrap (root = "/foo/bar/" )
6853
@@ -75,7 +60,6 @@ def test_bootstrapping_with_root(self):
7560 unittest .mock .ANY ,
7661 )
7762
78- @requires_usable_pip
7963 def test_bootstrapping_with_user (self ):
8064 ensurepip .bootstrap (user = True )
8165
@@ -87,7 +71,6 @@ def test_bootstrapping_with_user(self):
8771 unittest .mock .ANY ,
8872 )
8973
90- @requires_usable_pip
9174 def test_bootstrapping_with_upgrade (self ):
9275 ensurepip .bootstrap (upgrade = True )
9376
@@ -99,7 +82,6 @@ def test_bootstrapping_with_upgrade(self):
9982 unittest .mock .ANY ,
10083 )
10184
102- @requires_usable_pip
10385 def test_bootstrapping_with_verbosity_1 (self ):
10486 ensurepip .bootstrap (verbosity = 1 )
10587
@@ -111,7 +93,6 @@ def test_bootstrapping_with_verbosity_1(self):
11193 unittest .mock .ANY ,
11294 )
11395
114- @requires_usable_pip
11596 def test_bootstrapping_with_verbosity_2 (self ):
11697 ensurepip .bootstrap (verbosity = 2 )
11798
@@ -123,7 +104,6 @@ def test_bootstrapping_with_verbosity_2(self):
123104 unittest .mock .ANY ,
124105 )
125106
126- @requires_usable_pip
127107 def test_bootstrapping_with_verbosity_3 (self ):
128108 ensurepip .bootstrap (verbosity = 3 )
129109
@@ -135,17 +115,14 @@ def test_bootstrapping_with_verbosity_3(self):
135115 unittest .mock .ANY ,
136116 )
137117
138- @requires_usable_pip
139118 def test_bootstrapping_with_regular_install (self ):
140119 ensurepip .bootstrap ()
141120 self .assertEqual (self .os_environ ["ENSUREPIP_OPTIONS" ], "install" )
142121
143- @requires_usable_pip
144122 def test_bootstrapping_with_alt_install (self ):
145123 ensurepip .bootstrap (altinstall = True )
146124 self .assertEqual (self .os_environ ["ENSUREPIP_OPTIONS" ], "altinstall" )
147125
148- @requires_usable_pip
149126 def test_bootstrapping_with_default_pip (self ):
150127 ensurepip .bootstrap (default_pip = True )
151128 self .assertNotIn ("ENSUREPIP_OPTIONS" , self .os_environ )
@@ -155,15 +132,13 @@ def test_altinstall_default_pip_conflict(self):
155132 ensurepip .bootstrap (altinstall = True , default_pip = True )
156133 self .assertFalse (self .run_pip .called )
157134
158- @requires_usable_pip
159135 def test_pip_environment_variables_removed (self ):
160136 # ensurepip deliberately ignores all pip environment variables
161137 # See http://bugs.python.org/issue19734 for details
162138 self .os_environ ["PIP_THIS_SHOULD_GO_AWAY" ] = "test fodder"
163139 ensurepip .bootstrap ()
164140 self .assertNotIn ("PIP_THIS_SHOULD_GO_AWAY" , self .os_environ )
165141
166- @requires_usable_pip
167142 def test_pip_config_file_disabled (self ):
168143 # ensurepip deliberately ignores the pip config file
169144 # See http://bugs.python.org/issue20053 for details
@@ -205,7 +180,6 @@ def test_uninstall_skipped_with_warning_for_wrong_version(self):
205180 self .assertFalse (self .run_pip .called )
206181
207182
208- @requires_usable_pip
209183 def test_uninstall (self ):
210184 with fake_pip ():
211185 ensurepip ._uninstall_helper ()
@@ -217,7 +191,6 @@ def test_uninstall(self):
217191 ]
218192 )
219193
220- @requires_usable_pip
221194 def test_uninstall_with_verbosity_1 (self ):
222195 with fake_pip ():
223196 ensurepip ._uninstall_helper (verbosity = 1 )
@@ -229,7 +202,6 @@ def test_uninstall_with_verbosity_1(self):
229202 ]
230203 )
231204
232- @requires_usable_pip
233205 def test_uninstall_with_verbosity_2 (self ):
234206 with fake_pip ():
235207 ensurepip ._uninstall_helper (verbosity = 2 )
@@ -241,7 +213,6 @@ def test_uninstall_with_verbosity_2(self):
241213 ]
242214 )
243215
244- @requires_usable_pip
245216 def test_uninstall_with_verbosity_3 (self ):
246217 with fake_pip ():
247218 ensurepip ._uninstall_helper (verbosity = 3 )
@@ -253,7 +224,6 @@ def test_uninstall_with_verbosity_3(self):
253224 ]
254225 )
255226
256- @requires_usable_pip
257227 def test_pip_environment_variables_removed (self ):
258228 # ensurepip deliberately ignores all pip environment variables
259229 # See http://bugs.python.org/issue19734 for details
@@ -262,7 +232,6 @@ def test_pip_environment_variables_removed(self):
262232 ensurepip ._uninstall_helper ()
263233 self .assertNotIn ("PIP_THIS_SHOULD_GO_AWAY" , self .os_environ )
264234
265- @requires_usable_pip
266235 def test_pip_config_file_disabled (self ):
267236 # ensurepip deliberately ignores the pip config file
268237 # See http://bugs.python.org/issue20053 for details
@@ -271,44 +240,12 @@ def test_pip_config_file_disabled(self):
271240 self .assertEqual (self .os_environ ["PIP_CONFIG_FILE" ], os .devnull )
272241
273242
274- class TestMissingSSL (EnsurepipMixin , unittest .TestCase ):
275-
276- def setUp (self ):
277- sys .modules ["ensurepip" ] = ensurepip_no_ssl
278- @self .addCleanup
279- def restore_module ():
280- sys .modules ["ensurepip" ] = ensurepip
281- super ().setUp ()
282-
283- def test_bootstrap_requires_ssl (self ):
284- self .os_environ ["PIP_THIS_SHOULD_STAY" ] = "test fodder"
285- with self .assertRaisesRegex (RuntimeError , "requires SSL/TLS" ):
286- ensurepip_no_ssl .bootstrap ()
287- self .assertFalse (self .run_pip .called )
288- self .assertIn ("PIP_THIS_SHOULD_STAY" , self .os_environ )
289-
290- def test_uninstall_requires_ssl (self ):
291- self .os_environ ["PIP_THIS_SHOULD_STAY" ] = "test fodder"
292- with self .assertRaisesRegex (RuntimeError , "requires SSL/TLS" ):
293- with fake_pip ():
294- ensurepip_no_ssl ._uninstall_helper ()
295- self .assertFalse (self .run_pip .called )
296- self .assertIn ("PIP_THIS_SHOULD_STAY" , self .os_environ )
297-
298- def test_main_exits_early_with_warning (self ):
299- with test .support .captured_stderr () as stderr :
300- ensurepip_no_ssl ._main (["--version" ])
301- warning = stderr .getvalue ().strip ()
302- self .assertTrue (warning .endswith ("requires SSL/TLS" ), warning )
303- self .assertFalse (self .run_pip .called )
304-
305243# Basic testing of the main functions and their argument parsing
306244
307245EXPECTED_VERSION_OUTPUT = "pip " + ensurepip ._PIP_VERSION
308246
309247class TestBootstrappingMainFunction (EnsurepipMixin , unittest .TestCase ):
310248
311- @requires_usable_pip
312249 def test_bootstrap_version (self ):
313250 with test .support .captured_stdout () as stdout :
314251 with self .assertRaises (SystemExit ):
@@ -317,7 +254,6 @@ def test_bootstrap_version(self):
317254 self .assertEqual (result , EXPECTED_VERSION_OUTPUT )
318255 self .assertFalse (self .run_pip .called )
319256
320- @requires_usable_pip
321257 def test_basic_bootstrapping (self ):
322258 ensurepip ._main ([])
323259
@@ -342,7 +278,6 @@ def test_uninstall_version(self):
342278 self .assertEqual (result , EXPECTED_VERSION_OUTPUT )
343279 self .assertFalse (self .run_pip .called )
344280
345- @requires_usable_pip
346281 def test_basic_uninstall (self ):
347282 with fake_pip ():
348283 ensurepip ._uninstall ._main ([])
0 commit comments