6
6
import test .support
7
7
import unittest
8
8
import unittest .mock
9
- from pathlib import Path
10
9
11
10
import ensurepip
12
11
import ensurepip ._uninstall
13
12
14
13
15
14
class TestPackages (unittest .TestCase ):
16
- def setUp (self ):
17
- ensurepip ._get_usable_pip_package .cache_clear ()
18
-
19
- def tearDown (self ):
20
- ensurepip ._get_usable_pip_package .cache_clear ()
21
-
22
15
def touch (self , directory , filename ):
23
16
fullname = os .path .join (directory , filename )
24
17
open (fullname , "wb" ).close ()
@@ -27,43 +20,39 @@ def test_version(self):
27
20
# Test version()
28
21
with tempfile .TemporaryDirectory () as tmpdir :
29
22
self .touch (tmpdir , "pip-1.2.3b1-py2.py3-none-any.whl" )
30
- with unittest .mock .patch .object (
31
- ensurepip , '_WHEEL_PKG_DIR' , tmpdir ,
32
- ):
23
+ with unittest .mock .patch .object (ensurepip , '_WHEEL_PKG_DIR' , tmpdir ):
33
24
self .assertEqual (ensurepip .version (), '1.2.3b1' )
34
25
35
- def test_get_packages_no_dir (self ):
36
- # Test _get_packages () without a wheel package directory
26
+ def test_get_pip_info_no_dir (self ):
27
+ # Test _get_pip_info () without a wheel package directory
37
28
with unittest .mock .patch .object (ensurepip , '_WHEEL_PKG_DIR' , None ):
38
- pip_pkg = ensurepip ._get_usable_pip_package ()
29
+ pip_info = ensurepip ._get_pip_info ()
39
30
40
- # when bundled pip wheel package is used, we get _PIP_VERSION
31
+ # when the bundled pip wheel is used, we get _PIP_VERSION
41
32
self .assertEqual (ensurepip ._PIP_VERSION , ensurepip .version ())
42
33
43
- # use bundled pip wheel package
44
- self .assertIsNotNone (pip_pkg .wheel_name )
34
+ # use the bundled pip wheel
35
+ pip_filename = f'pip-{ ensurepip ._PIP_VERSION } -py3-none-any.whl'
36
+ expected = {"version" : ensurepip ._PIP_VERSION , "filename" : pip_filename ,
37
+ "bundled" : True }
38
+ self .assertDictEqual (pip_info , expected )
45
39
46
- def test_get_packages_with_dir (self ):
47
- # Test _get_packages() with a wheel package directory
48
- older_pip_filename = "pip-1.2.3-py2.py3-none-any.whl"
40
+ def test_get_pip_info_with_dir (self ):
41
+ # Test _get_pip_info() with a wheel package directory
49
42
pip_filename = "pip-20.2.2-py2.py3-none-any.whl"
50
43
51
44
with tempfile .TemporaryDirectory () as tmpdir :
52
- self .touch (tmpdir , older_pip_filename )
53
45
self .touch (tmpdir , pip_filename )
54
- # not used, make sure that it's ignored
46
+ # not used, make sure that they're ignored
47
+ self .touch (tmpdir , "pip-1.2.3-py2.py3-none-any.whl" )
55
48
self .touch (tmpdir , "wheel-0.34.2-py2.py3-none-any.whl" )
56
- # not used, make sure that it's ignored
57
- self .touch (tmpdir , "non-whl" )
49
+ self .touch (tmpdir , "pip-script.py" )
58
50
59
- with unittest .mock .patch .object (
60
- ensurepip , '_WHEEL_PKG_DIR' , tmpdir ,
61
- ):
62
- pip_pkg = ensurepip ._get_usable_pip_package ()
51
+ with unittest .mock .patch .object (ensurepip , '_WHEEL_PKG_DIR' , tmpdir ):
52
+ pip_info = ensurepip ._get_pip_info ()
63
53
64
- self .assertEqual (pip_pkg .version , '20.2.2' )
65
- self .assertEqual (pip_pkg .wheel_path ,
66
- os .path .join (tmpdir , pip_filename ))
54
+ expected = {"version" : '20.2.2' , "filename" : pip_filename , "bundled" : False }
55
+ self .assertDictEqual (pip_info , expected )
67
56
68
57
69
58
class EnsurepipMixin :
@@ -102,30 +91,6 @@ def test_basic_bootstrapping(self):
102
91
additional_paths = self .run_pip .call_args [0 ][1 ]
103
92
self .assertEqual (len (additional_paths ), 1 )
104
93
105
-
106
- def test_replacement_wheel_bootstrapping (self ):
107
- ensurepip ._get_usable_pip_package .cache_clear ()
108
-
109
- pip_wheel_name = (
110
- f'pip-{ ensurepip ._PIP_VERSION !s} -'
111
- 'py3-none-any.whl'
112
- )
113
-
114
- with tempfile .TemporaryDirectory () as tmpdir :
115
- tmp_path = Path (tmpdir )
116
- tmp_wheel_path = tmp_path / pip_wheel_name
117
- tmp_wheel_path .touch ()
118
-
119
- with unittest .mock .patch .object (
120
- ensurepip , '_WHEEL_PKG_DIR' , tmpdir ,
121
- ):
122
- ensurepip .bootstrap ()
123
-
124
- ensurepip ._get_usable_pip_package .cache_clear ()
125
-
126
- additional_paths = self .run_pip .call_args [0 ][1 ]
127
- self .assertEqual (Path (additional_paths [- 1 ]).name , pip_wheel_name )
128
-
129
94
def test_bootstrapping_with_root (self ):
130
95
ensurepip .bootstrap (root = "/foo/bar/" )
131
96
0 commit comments