File: test_uninstall.py

package info (click to toggle)
pipenv 2024.0.1%2Bds-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 18,568 kB
  • sloc: python: 187,163; makefile: 191; javascript: 133; sh: 64
file content (329 lines) | stat: -rw-r--r-- 9,993 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
import pytest
import sys

from .conftest import DEFAULT_PRIVATE_PYPI_SERVER

from pipenv.utils.shell import temp_environ


@pytest.mark.uninstall
@pytest.mark.install
def test_uninstall_requests(pipenv_instance_pypi):
    with pipenv_instance_pypi() as p:
        c = p.pipenv("install requests")
        assert c.returncode == 0
        assert "requests" in p.pipfile["packages"]

        c = p.pipenv("uninstall requests")
        assert c.returncode == 0
        assert "requests" not in p.pipfile["packages"]
        assert "requests" not in p.lockfile["default"]


@pytest.mark.uninstall
@pytest.mark.skipif(sys.version_info >= (3, 12), reason="Package does not work with Python 3.12")
def test_uninstall_django(pipenv_instance_private_pypi):
    with pipenv_instance_private_pypi() as p:
        c = p.pipenv("install Django")
        assert c.returncode == 0
        assert "django" in p.pipfile["packages"]
        assert "django" in p.lockfile["default"]
        assert "pytz" in p.lockfile["default"]

        c = p.pipenv("run python -m django --version")
        assert c.returncode == 0

        c = p.pipenv("uninstall Django")
        assert c.returncode == 0
        assert "django" not in p.pipfile["dev-packages"]
        assert "django" not in p.lockfile["develop"]
        assert p.lockfile["develop"] == {}

        c = p.pipenv("run python -m django --version")
        assert c.returncode > 0


@pytest.mark.install
@pytest.mark.uninstall
@pytest.mark.skipif(sys.version_info >= (3, 12), reason="Package does not work with Python 3.12")
def test_mirror_uninstall(pipenv_instance_pypi):
    with temp_environ(), pipenv_instance_pypi() as p:

        mirror_url = DEFAULT_PRIVATE_PYPI_SERVER
        assert "pypi.org" not in mirror_url

        c = p.pipenv(f"install Django --pypi-mirror {mirror_url}")
        assert c.returncode == 0
        assert "django" in p.pipfile["packages"]
        assert "django" in p.lockfile["default"]
        assert "pytz" in p.lockfile["default"]
        # Ensure the --pypi-mirror parameter hasn't altered the Pipfile or Pipfile.lock sources
        assert len(p.pipfile["source"]) == 1
        assert len(p.lockfile["_meta"]["sources"]) == 1
        assert p.pipfile["source"][0]["url"] == "https://pypi.org/simple"
        assert p.lockfile["_meta"]["sources"][0]["url"] == "https://pypi.org/simple"

        c = p.pipenv("run python -m django --version")
        assert c.returncode == 0

        c = p.pipenv(f"uninstall Django --pypi-mirror {mirror_url}")
        assert c.returncode == 0
        assert "django" not in p.pipfile["dev-packages"]
        assert "django" not in p.lockfile["develop"]
        assert p.lockfile["develop"] == {}
        # Ensure the --pypi-mirror parameter hasn't altered the Pipfile or Pipfile.lock sources
        assert len(p.pipfile["source"]) == 1
        assert len(p.lockfile["_meta"]["sources"]) == 1
        assert p.pipfile["source"][0]["url"] == "https://pypi.org/simple"
        assert p.lockfile["_meta"]["sources"][0]["url"] == "https://pypi.org/simple"

        c = p.pipenv("run python -m django --version")
        assert c.returncode > 0


@pytest.mark.files
@pytest.mark.install
@pytest.mark.uninstall
def test_uninstall_all_local_files(pipenv_instance_private_pypi, testsroot):
    with pipenv_instance_private_pypi() as p:
        file_uri = p._pipfile.get_fixture_path("tablib/tablib-0.12.1.tar.gz", fixtures="pypi").as_uri()
        c = p.pipenv(f"install {file_uri}")
        assert c.returncode == 0
        c = p.pipenv("uninstall --all")
        assert "tablib" not in p.pipfile["packages"]
        assert "tablib" not in p.lockfile["default"]


@pytest.mark.install
@pytest.mark.uninstall
def test_uninstall_all_dev(pipenv_instance_private_pypi):
    with pipenv_instance_private_pypi() as p:
        with open(p.pipfile_path, "w") as f:
            contents = f"""
[[source]]
name = "pypi"
url = "{p.index_url}"
verify_ssl = true

[packages]
tablib = "*"

[dev-packages]
jinja2 = "==2.11.1"
six = "==1.12.0"
        """
            f.write(contents)

        c = p.pipenv("install --dev")
        assert c.returncode == 0

        assert "tablib" in p.pipfile["packages"]
        assert "jinja2" in p.pipfile["dev-packages"]
        assert "six" in p.pipfile["dev-packages"]
        assert "tablib" in p.lockfile["default"]
        assert "jinja2" in p.lockfile["develop"]
        assert "six" in p.lockfile["develop"]
        assert c.returncode == 0

        c = p.pipenv("uninstall --all-dev")
        assert c.returncode == 0
        assert p.pipfile["dev-packages"] == {}
        assert "jinja2" not in p.lockfile["develop"]
        assert "six" not in p.lockfile["develop"]
        assert "tablib" in p.pipfile["packages"]
        assert "tablib" in p.lockfile["default"]

        c = p.pipenv('run python -c "import jinja2"')
        assert c.returncode > 0

        c = p.pipenv('run python -c "import tablib"')
        assert c.returncode == 0


@pytest.mark.install
@pytest.mark.uninstall
def test_normalize_name_uninstall(pipenv_instance_private_pypi):
    with pipenv_instance_private_pypi() as p:
        with open(p.pipfile_path, "w") as f:
            contents = """
# Pre comment
[packages]
Requests = "*"
python_DateUtil = "*"
"""
            f.write(contents)

        c = p.pipenv("install")
        assert c.returncode == 0

        c = p.pipenv("uninstall python_dateutil")
        assert "Requests" in p.pipfile["packages"]
        assert "python_DateUtil" not in p.pipfile["packages"]
        with open(p.pipfile_path) as f:
            contents = f.read()
            assert "# Pre comment" in contents


@pytest.mark.install
@pytest.mark.uninstall
def test_uninstall_all_dev_with_shared_dependencies(pipenv_instance_pypi):
    with pipenv_instance_pypi() as p:
        with open(p.pipfile_path, "w") as f:
            contents = """
        [packages]
        pytest = "==4.6.11"

        [dev-packages]
        six = "*"
        """
            f.write(contents)
        c = p.pipenv("install")
        assert c.returncode == 0

        c = p.pipenv("uninstall --all-dev")
        assert c.returncode == 0

        assert "six" in p.lockfile["default"]


@pytest.mark.install
@pytest.mark.uninstall
def test_uninstall_missing_parameters(pipenv_instance_private_pypi):
    with pipenv_instance_private_pypi() as p:
        c = p.pipenv("install six")
        assert c.returncode == 0

        c = p.pipenv("uninstall")
        assert c.returncode != 0
        assert "No package provided!" in c.stderr


@pytest.mark.categories
@pytest.mark.install
@pytest.mark.uninstall
def test_uninstall_category_with_shared_requirement(pipenv_instance_pypi):
    with pipenv_instance_pypi() as p:
        with open(p.pipfile_path, "w") as f:
            contents = """
        [packages]
        six = "*"

        [prereq]
        six = "*"
        """
            f.write(contents)
        c = p.pipenv("install")
        assert c.returncode == 0

        c = p.pipenv("uninstall six --categories default")
        assert c.returncode == 0

        assert "six" in p.lockfile["prereq"]
        assert "six" not in p.lockfile["default"]


@pytest.mark.categories
@pytest.mark.install
@pytest.mark.uninstall
def test_uninstall_multiple_categories(pipenv_instance_private_pypi):
    with pipenv_instance_private_pypi() as p:
        with open(p.pipfile_path, "w") as f:
            contents = """
        [after]
        six = "==1.12.0"

        [prereq]
        six = "==1.12.0"
        """
            f.write(contents)
        c = p.pipenv("install")
        assert c.returncode == 0

        c = p.pipenv('uninstall six --categories="prereq after"')
        assert c.returncode == 0

        assert "six" not in p.lockfile.get("prereq", {})
        assert "six" not in p.lockfile["default"]


@pytest.mark.install
@pytest.mark.uninstall
def test_category_sorted_alphabetically_with_directive(pipenv_instance_private_pypi):
    with pipenv_instance_private_pypi() as p:
        with open(p.pipfile_path, "w") as f:
            contents = """
[pipenv]
sort_pipfile = true

[packages]
parse = "*"
colorama = "*"
build = "*"
atomicwrites = "*"
            """.strip()
            f.write(contents)

        c = p.pipenv("install")
        assert c.returncode == 0

        c = p.pipenv("uninstall build")
        assert c.returncode == 0
        assert "build" not in p.pipfile["packages"]
        assert list(p.pipfile["packages"].keys()) == ["atomicwrites", "colorama", "parse"]


@pytest.mark.install
@pytest.mark.uninstall
def test_sorting_handles_str_values_and_dict_values(pipenv_instance_private_pypi):
    with pipenv_instance_private_pypi() as p:
        with open(p.pipfile_path, "w") as f:
            contents = """
[pipenv]
sort_pipfile = true

[packages]
zipp = "*"
parse = {version = "*"}
colorama = "*"
build = "*"
atomicwrites = {version = "*"}
            """.strip()
            f.write(contents)
        c = p.pipenv("install")
        assert c.returncode == 0

        c = p.pipenv("uninstall build")
        assert c.returncode == 0
        assert "build" not in p.pipfile["packages"]
        assert list(p.pipfile["packages"].keys()) == [
            "atomicwrites",
            "colorama",
            "parse",
            "zipp",
        ]

@pytest.mark.install
@pytest.mark.uninstall
def test_category_not_sorted_without_directive(pipenv_instance_private_pypi):
    with pipenv_instance_private_pypi() as p:
        with open(p.pipfile_path, "w") as f:
            contents = """
[packages]
parse = "*"
colorama = "*"
build = "*"
atomicwrites = "*"
            """.strip()
            f.write(contents)

        c = p.pipenv("install")
        assert c.returncode == 0

        c = p.pipenv("uninstall build")
        assert c.returncode == 0
        assert "build" not in p.pipfile["packages"]
        assert list(p.pipfile["packages"].keys()) == [
            "parse",
            "colorama",
            "atomicwrites",
        ]