15
15
from pip ._internal .req .req_install import InstallRequirement
16
16
from pip ._internal .utils .compat import WINDOWS
17
17
from pip ._internal .utils .misc import unpack_file
18
- from tests .lib import DATA_DIR
18
+ from tests .lib import DATA_DIR , assert_paths_equal
19
19
20
20
21
21
@pytest .mark .parametrize (
@@ -38,25 +38,13 @@ def test_contains_egg_info(s, expected):
38
38
assert result == expected
39
39
40
40
41
- @pytest .mark .parametrize (
42
- "base_name, autobuilding, cache_available, expected" ,
43
- [
44
- ('pendulum-2.0.4' , False , False , False ),
45
- # The following cases test autobuilding=True.
46
- # Test _contains_egg_info() returning True.
47
- ('pendulum-2.0.4' , True , True , False ),
48
- ('pendulum-2.0.4' , True , False , True ),
49
- # Test _contains_egg_info() returning False.
50
- ('pendulum' , True , True , True ),
51
- ('pendulum' , True , False , True ),
52
- ],
53
- )
54
- def test_should_use_ephemeral_cache__issue_6197 (
55
- base_name , autobuilding , cache_available , expected ,
56
- ):
41
+ def make_test_install_req (base_name = None ):
57
42
"""
58
- Regression test for: https://github.com/pypa/pip/issues/6197
43
+ Return an InstallRequirement object for testing purposes.
59
44
"""
45
+ if base_name is None :
46
+ base_name = 'pendulum-2.0.4'
47
+
60
48
req = Requirement ('pendulum' )
61
49
link_url = (
62
50
'https://files.pythonhosted.org/packages/aa/{base_name}.tar.gz'
@@ -76,6 +64,30 @@ def test_should_use_ephemeral_cache__issue_6197(
76
64
link = link ,
77
65
source_dir = '/tmp/pip-install-9py5m2z1/pendulum' ,
78
66
)
67
+
68
+ return req
69
+
70
+
71
+ @pytest .mark .parametrize (
72
+ "base_name, autobuilding, cache_available, expected" ,
73
+ [
74
+ ('pendulum-2.0.4' , False , False , False ),
75
+ # The following cases test autobuilding=True.
76
+ # Test _contains_egg_info() returning True.
77
+ ('pendulum-2.0.4' , True , True , False ),
78
+ ('pendulum-2.0.4' , True , False , True ),
79
+ # Test _contains_egg_info() returning False.
80
+ ('pendulum' , True , True , True ),
81
+ ('pendulum' , True , False , True ),
82
+ ],
83
+ )
84
+ def test_should_use_ephemeral_cache__issue_6197 (
85
+ base_name , autobuilding , cache_available , expected ,
86
+ ):
87
+ """
88
+ Regression test for: https://github.com/pypa/pip/issues/6197
89
+ """
90
+ req = make_test_install_req (base_name = base_name )
79
91
assert not req .is_wheel
80
92
assert req .link .is_artifact
81
93
@@ -87,6 +99,59 @@ def test_should_use_ephemeral_cache__issue_6197(
87
99
assert ephem_cache is expected
88
100
89
101
102
+ def call_get_legacy_build_wheel_path (caplog , names ):
103
+ req = make_test_install_req ()
104
+ wheel_path = wheel .get_legacy_build_wheel_path (
105
+ names = names ,
106
+ temp_dir = '/tmp/abcd' ,
107
+ req = req ,
108
+ command_args = ['arg1' , 'arg2' ],
109
+ command_output = 'output line 1\n output line 2\n ' ,
110
+ )
111
+ return wheel_path
112
+
113
+
114
+ def test_get_legacy_build_wheel_path (caplog ):
115
+ actual = call_get_legacy_build_wheel_path (caplog , names = ['name' ])
116
+ assert_paths_equal (actual , '/tmp/abcd/name' )
117
+ assert not caplog .records
118
+
119
+
120
+ def test_get_legacy_build_wheel_path__no_names (caplog ):
121
+ actual = call_get_legacy_build_wheel_path (caplog , names = [])
122
+ assert actual is None
123
+ assert len (caplog .records ) == 1
124
+ record = caplog .records [0 ]
125
+ assert record .levelname == 'ERROR'
126
+ assert record .message .splitlines () == [
127
+ "Failed building wheel for pendulum with args: ['arg1', 'arg2']" ,
128
+ "Command output:" ,
129
+ "output line 1" ,
130
+ "output line 2" ,
131
+ "-----------------------------------------" ,
132
+ ]
133
+
134
+
135
+ def test_get_legacy_build_wheel_path__multiple_names (caplog ):
136
+ # Deliberately pass the names in non-sorted order.
137
+ actual = call_get_legacy_build_wheel_path (
138
+ caplog , names = ['name2' , 'name1' ],
139
+ )
140
+ assert_paths_equal (actual , '/tmp/abcd/name1' )
141
+ assert len (caplog .records ) == 1
142
+ record = caplog .records [0 ]
143
+ assert record .levelname == 'WARNING'
144
+ assert record .message .splitlines () == [
145
+ ("Found more than one file after building wheel for pendulum "
146
+ "with args: ['arg1', 'arg2']" ),
147
+ "Names: ['name1', 'name2']" ,
148
+ "Command output:" ,
149
+ "output line 1" ,
150
+ "output line 2" ,
151
+ "-----------------------------------------" ,
152
+ ]
153
+
154
+
90
155
@pytest .mark .parametrize ("console_scripts" ,
91
156
["pip = pip._internal.main:pip" ,
92
157
"pip:pip = pip._internal.main:pip" ])
0 commit comments