-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
/
test_install_basic.py
808 lines (683 loc) · 24.1 KB
/
test_install_basic.py
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
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
import json
import os
import re
import sys
from pathlib import Path
from tempfile import TemporaryDirectory
import pytest
from pipenv.utils.processes import subprocess_run
from pipenv.utils.shell import temp_environ
@pytest.mark.basic
@pytest.mark.install
def test_basic_install(pipenv_instance_private_pypi):
with pipenv_instance_private_pypi() as p:
c = p.pipenv("install six -v")
assert c.returncode == 0
assert "six" in p.pipfile["packages"]
assert "six" in p.lockfile["default"]
@pytest.mark.basic
@pytest.mark.install
def test_mirror_install(pipenv_instance_pypi):
with temp_environ(), pipenv_instance_pypi() as p:
mirror_url = "https://pypi.python.org/simple"
assert "pypi.org" not in mirror_url
# This should sufficiently demonstrate the mirror functionality
c = p.pipenv(f"install dataclasses-json --pypi-mirror {mirror_url}")
assert c.returncode == 0
# 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"
assert "dataclasses-json" in p.pipfile["packages"]
assert "dataclasses-json" in p.lockfile["default"]
@pytest.mark.basic
@pytest.mark.install
@pytest.mark.needs_internet
def test_bad_mirror_install(pipenv_instance_pypi):
with temp_environ(), pipenv_instance_pypi() as p:
# This demonstrates that the mirror parameter is being used
c = p.pipenv("install dataclasses-json --pypi-mirror https://pypi.example.org")
assert c.returncode != 0
@pytest.mark.dev
@pytest.mark.run
def test_basic_dev_install(pipenv_instance_pypi):
with pipenv_instance_pypi() as p:
c = p.pipenv("install dataclasses-json --dev")
assert c.returncode == 0
assert "dataclasses-json" in p.pipfile["dev-packages"]
assert "dataclasses-json" in p.lockfile["develop"]
c = p.pipenv("""run python -c "from dataclasses_json import dataclass_json" """)
assert c.returncode == 0
@pytest.mark.dev
@pytest.mark.basic
@pytest.mark.install
def test_install_without_dev(pipenv_instance_private_pypi):
"""Ensure that running `pipenv install` doesn't install dev packages"""
with pipenv_instance_private_pypi() as p:
with open(p.pipfile_path, "w") as f:
contents = """
[packages]
six = "*"
[dev-packages]
tablib = "*"
""".strip()
f.write(contents)
c = p.pipenv("install")
assert c.returncode == 0
assert "six" in p.pipfile["packages"]
assert "tablib" in p.pipfile["dev-packages"]
assert "six" in p.lockfile["default"]
assert "tablib" in p.lockfile["develop"]
c = p.pipenv('run python -c "import tablib"')
assert c.returncode != 0
c = p.pipenv('run python -c "import six"')
assert c.returncode == 0
@pytest.mark.basic
@pytest.mark.install
def test_install_with_version_req_default_operator(pipenv_instance_private_pypi):
"""Ensure that running `pipenv install` work when spec is package = "X.Y.Z"."""
with pipenv_instance_private_pypi() as p:
with open(p.pipfile_path, "w") as f:
contents = """
[packages]
six = "1.12.0"
""".strip()
f.write(contents)
c = p.pipenv("install")
assert c.returncode == 0
assert "six" in p.pipfile["packages"]
@pytest.mark.basic
@pytest.mark.install
def test_install_without_dev_section(pipenv_instance_pypi):
with pipenv_instance_pypi() as p:
with open(p.pipfile_path, "w") as f:
contents = """
[packages]
six = "*"
""".strip()
f.write(contents)
c = p.pipenv("install")
assert c.returncode == 0
assert "six" in p.pipfile["packages"]
assert p.pipfile.get("dev-packages", {}) == {}
assert "six" in p.lockfile["default"]
assert p.lockfile["develop"] == {}
c = p.pipenv('run python -c "import six"')
assert c.returncode == 0
@pytest.mark.lock
@pytest.mark.extras
@pytest.mark.install
def test_extras_install(pipenv_instance_private_pypi):
with pipenv_instance_private_pypi() as p:
c = p.pipenv("install requests[socks]")
assert c.returncode == 0
assert "requests" in p.pipfile["packages"]
assert "extras" in p.pipfile["packages"]["requests"]
assert "requests" in p.lockfile["default"]
assert "chardet" in p.lockfile["default"]
assert "idna" in p.lockfile["default"]
assert "urllib3" in p.lockfile["default"]
assert "pysocks" in p.lockfile["default"]
@pytest.mark.pin
@pytest.mark.basic
@pytest.mark.install
def test_pinned_pipfile(pipenv_instance_pypi):
with pipenv_instance_pypi() as p:
with open(p.pipfile_path, "w") as f:
contents = """
[packages]
dataclasses-json = "==0.5.7"
""".strip()
f.write(contents)
c = p.pipenv("install")
assert c.returncode == 0
assert "dataclasses-json" in p.pipfile["packages"]
assert "dataclasses-json" in p.lockfile["default"]
@pytest.mark.basic
@pytest.mark.install
@pytest.mark.resolver
@pytest.mark.backup_resolver
@pytest.mark.skipif(
sys.version_info >= (3, 12), reason="Package does not work with Python 3.12"
)
def test_backup_resolver(pipenv_instance_private_pypi):
with pipenv_instance_private_pypi() as p:
with open(p.pipfile_path, "w") as f:
contents = """
[packages]
"ibm-db-sa-py3" = "==0.3.1-1"
""".strip()
f.write(contents)
c = p.pipenv("install")
assert c.returncode == 0
assert "ibm-db-sa-py3" in p.lockfile["default"]
@pytest.mark.run
@pytest.mark.alt
def test_alternative_version_specifier(pipenv_instance_private_pypi):
with pipenv_instance_private_pypi() as p:
with open(p.pipfile_path, "w") as f:
contents = """
[packages]
six = {version = "*"}
""".strip()
f.write(contents)
c = p.pipenv("install -v")
assert c.returncode == 0
assert "six" in p.lockfile["default"]
c = p.pipenv('run python -c "import six;"')
assert c.returncode == 0
@pytest.mark.run
@pytest.mark.alt
def test_outline_table_specifier(pipenv_instance_private_pypi):
with pipenv_instance_private_pypi() as p:
with open(p.pipfile_path, "w") as f:
contents = """
[packages.six]
version = "*"
""".strip()
f.write(contents)
c = p.pipenv("install")
assert c.returncode == 0
assert "six" in p.lockfile["default"]
c = p.pipenv('run python -c "import six;"')
assert c.returncode == 0
@pytest.mark.bad
@pytest.mark.basic
@pytest.mark.install
def test_bad_packages(pipenv_instance_private_pypi):
with pipenv_instance_private_pypi() as p:
c = p.pipenv("install NotAPackage")
assert c.returncode > 0
@pytest.mark.lock
@pytest.mark.extras
@pytest.mark.install
@pytest.mark.requirements
def test_requirements_to_pipfile(pipenv_instance_private_pypi):
with pipenv_instance_private_pypi(pipfile=False) as p:
# Write a requirements file
with open("requirements.txt", "w") as f:
f.write(f"-i {p.index_url}\nrequests[socks]==2.19.1\n")
c = p.pipenv("install")
assert c.returncode == 0
os.unlink("requirements.txt")
print(c.stdout)
print(c.stderr)
# assert stuff in pipfile
assert "requests" in p.pipfile["packages"]
assert "extras" in p.pipfile["packages"]["requests"]
assert not any(
source["url"] == "https://private.pypi.org/simple"
for source in p.pipfile["source"]
)
# assert stuff in lockfile
assert "requests" in p.lockfile["default"]
assert "chardet" in p.lockfile["default"]
assert "idna" in p.lockfile["default"]
assert "urllib3" in p.lockfile["default"]
assert "pysocks" in p.lockfile["default"]
@pytest.mark.basic
@pytest.mark.install
@pytest.mark.requirements
def test_skip_requirements_when_pipfile(pipenv_instance_private_pypi):
"""Ensure requirements.txt is NOT imported when
1. We do `pipenv install [package]`
2. A Pipfile already exists when we run `pipenv install`.
"""
with pipenv_instance_private_pypi() as p:
with open("requirements.txt", "w") as f:
f.write("requests==2.18.1\n")
c = p.pipenv("install six")
assert c.returncode == 0
with open(p.pipfile_path, "w") as f:
contents = """
[packages]
six = "*"
""".strip()
f.write(contents)
c = p.pipenv("install")
assert c.returncode == 0
assert "six" in p.pipfile["packages"]
assert "six" in p.lockfile["default"]
assert "requests" not in p.pipfile["packages"]
assert "requests" not in p.lockfile["default"]
@pytest.mark.cli
@pytest.mark.clean
def test_clean_on_empty_venv(pipenv_instance_pypi):
with pipenv_instance_pypi() as p:
c = p.pipenv("clean")
assert c.returncode == 0
@pytest.mark.basic
@pytest.mark.install
def test_install_does_not_extrapolate_environ(pipenv_instance_private_pypi):
"""Ensure environment variables are not expanded in lock file."""
with temp_environ(), pipenv_instance_private_pypi() as p:
os.environ["PYPI_URL"] = p.pypi
with open(p.pipfile_path, "w") as f:
f.write(
"""
[[source]]
url = '${PYPI_URL}/simple'
verify_ssl = true
name = 'mockpi'
"""
)
# Ensure simple install does not extrapolate.
c = p.pipenv("install -v")
assert c.returncode == 0
assert p.pipfile["source"][0]["url"] == "${PYPI_URL}/simple"
assert p.lockfile["_meta"]["sources"][0]["url"] == "${PYPI_URL}/simple"
# Ensure package install does not extrapolate.
c = p.pipenv("install six -v")
assert c.returncode == 0
assert p.pipfile["source"][0]["url"] == "${PYPI_URL}/simple"
assert p.lockfile["_meta"]["sources"][0]["url"] == "${PYPI_URL}/simple"
@pytest.mark.basic
@pytest.mark.editable
@pytest.mark.badparameter
@pytest.mark.install
def test_editable_no_args(pipenv_instance_pypi):
with pipenv_instance_pypi() as p:
c = p.pipenv("install -e")
assert c.returncode != 0
assert "Error: Option '-e' requires an argument" in c.stderr
@pytest.mark.basic
@pytest.mark.install
@pytest.mark.virtualenv
def test_install_venv_project_directory(pipenv_instance_pypi):
"""Test the project functionality during virtualenv creation."""
with pipenv_instance_pypi() as p, temp_environ(), TemporaryDirectory(
prefix="pipenv-", suffix="temp_workon_home"
) as workon_home:
os.environ["WORKON_HOME"] = workon_home
c = p.pipenv("install six")
assert c.returncode == 0
venv_loc_patt = r"Virtualenv location:(.*?)(?=Pipfile\.lock)"
match = re.search(venv_loc_patt, c.stderr, re.DOTALL)
assert match
# Extract the matched text
venv_loc = match.group(1).strip()
venv_loc = Path(venv_loc)
assert venv_loc.joinpath(".project").exists()
@pytest.mark.cli
@pytest.mark.deploy
@pytest.mark.system
def test_system_and_deploy_work(pipenv_instance_private_pypi):
with pipenv_instance_private_pypi() as p:
c = p.pipenv("install urllib3")
assert c.returncode == 0
c = p.pipenv("--rm")
assert c.returncode == 0
c = subprocess_run(["virtualenv", ".venv"])
assert c.returncode == 0
c = p.pipenv("install --system --deploy")
assert c.returncode == 0
@pytest.mark.cli
@pytest.mark.deploy
@pytest.mark.system
def test_system_works(pipenv_instance_pypi):
with pipenv_instance_pypi() as p:
c = p.pipenv("install urllib3")
assert c.returncode == 0
c = p.pipenv("--rm")
assert c.returncode == 0
c = subprocess_run(["virtualenv", ".venv"])
assert c.returncode == 0
c = p.pipenv("install --system")
assert c.returncode == 0
@pytest.mark.basic
@pytest.mark.install
def test_install_creates_pipfile(pipenv_instance_pypi):
with pipenv_instance_pypi(pipfile=False) as p:
assert not os.path.isfile(p.pipfile_path)
c = p.pipenv("install")
assert c.returncode == 0
assert os.path.isfile(p.pipfile_path)
python_version = str(sys.version_info.major) + "." + str(sys.version_info.minor)
assert p.pipfile["requires"] == {"python_version": python_version}
@pytest.mark.basic
@pytest.mark.install
def test_create_pipfile_requires_python_full_version(pipenv_instance_private_pypi):
with pipenv_instance_private_pypi(pipfile=False) as p:
python_version = f"{sys.version_info.major}.{sys.version_info.minor}"
python_full_version = f"{python_version}.{sys.version_info.micro}"
c = p.pipenv(f"--python {python_full_version}")
assert c.returncode == 0
assert p.pipfile["requires"] == {
"python_full_version": python_full_version,
"python_version": python_version,
}
@pytest.mark.basic
@pytest.mark.install
@pytest.mark.virtualenv
def test_install_with_pipfile_including_exact_python_version(pipenv_instance_pypi):
valid_version = f"{sys.version_info.major}.{sys.version_info.minor}"
with pipenv_instance_pypi() as p:
with open(p.pipfile_path, "w") as f:
f.write(
f"""
[[source]]
url = "https://test.pypi.org/simple"
verify_ssl = true
name = "testpypi"
[packages]
pytz = "*"
[requires]
python_version = "{valid_version}"
"""
)
c = p.pipenv("install")
assert c.returncode == 0
assert os.path.isfile(p.pipfile_path)
assert p.pipfile["requires"]["python_version"] == valid_version
c = p.pipenv("--rm")
assert c.returncode == 0
@pytest.mark.basic
@pytest.mark.install
@pytest.mark.virtualenv
def test_install_with_pipfile_including_invalid_python_version(pipenv_instance_pypi):
invalid_versions = [
f">={sys.version_info.major}.{sys.version_info.minor}",
f"<={sys.version_info.major}.{sys.version_info.minor}",
f">{sys.version_info.major}.{sys.version_info.minor}",
f"<{sys.version_info.major}.{sys.version_info.minor}",
]
with pipenv_instance_pypi() as p:
for version in invalid_versions:
with open(p.pipfile_path, "w") as f:
f.write(
f"""
[[source]]
url = "https://test.pypi.org/simple"
verify_ssl = true
name = "testpypi"
[packages]
pytz = "*"
[requires]
python_version = "{version}"
"""
)
c = p.pipenv("install")
assert c.returncode != 0
@pytest.mark.basic
@pytest.mark.install
def test_install_non_exist_dep(pipenv_instance_pypi):
with pipenv_instance_pypi() as p:
c = p.pipenv("install dateutil")
assert c.returncode
assert "dateutil" not in p.pipfile["packages"]
@pytest.mark.basic
@pytest.mark.install
def test_install_package_with_dots(pipenv_instance_private_pypi):
with pipenv_instance_private_pypi() as p:
c = p.pipenv("install backports.html")
assert c.returncode == 0
assert "backports.html" in p.pipfile["packages"]
@pytest.mark.basic
@pytest.mark.install
def test_rewrite_outline_table(pipenv_instance_private_pypi):
with pipenv_instance_private_pypi() as p:
with open(p.pipfile_path, "w") as f:
contents = """
[[source]]
url = "{}"
verify_ssl = false
name = "testindex"
[packages]
six = {}
[packages.requests]
version = "*"
extras = ["socks"]
""".format(
p.index_url, '{version = "*"}'
).strip()
f.write(contents)
c = p.pipenv("install colorama")
assert c.returncode == 0
with open(p.pipfile_path) as f:
contents = f.read()
assert "[packages.requests]" not in contents
assert 'six = {version = "*"}' in contents
assert 'requests = {version = "*"' in contents
assert 'colorama = "*"' in contents
@pytest.mark.basic
@pytest.mark.install
def test_rewrite_outline_table_ooo(pipenv_instance_private_pypi):
with pipenv_instance_private_pypi() as p:
with open(p.pipfile_path, "w") as f:
contents = """
[[source]]
url = "{}"
verify_ssl = false
name = "testindex"
[packages]
six = {}
# Out-of-order
[pipenv]
allow_prereleases = false
[packages.requests]
version = "*"
extras = ["socks"]
""".format(
p.index_url, '{version = "*"}'
).strip()
f.write(contents)
c = p.pipenv("install colorama")
assert c.returncode == 0
with open(p.pipfile_path) as f:
contents = f.read()
assert "[packages.requests]" not in contents
assert 'six = {version = "*"}' in contents
assert 'requests = {version = "*"' in contents
assert 'colorama = "*"' in contents
@pytest.mark.dev
@pytest.mark.install
def test_install_dev_use_default_constraints(pipenv_instance_private_pypi):
# See https://github.com/pypa/pipenv/issues/4371
# See https://github.com/pypa/pipenv/issues/2987
with pipenv_instance_private_pypi() as p:
c = p.pipenv("install requests==2.14.0")
assert c.returncode == 0
assert "requests" in p.lockfile["default"]
assert p.lockfile["default"]["requests"]["version"] == "==2.14.0"
c = p.pipenv("install --dev requests")
assert c.returncode == 0
assert "requests" in p.lockfile["develop"]
assert p.lockfile["develop"]["requests"]["version"] == "==2.14.0"
# requests 2.14.0 doesn't require these packages
assert "idna" not in p.lockfile["develop"]
assert "certifi" not in p.lockfile["develop"]
assert "urllib3" not in p.lockfile["develop"]
assert "chardet" not in p.lockfile["develop"]
c = p.pipenv("run python -c 'import urllib3'")
assert c.returncode != 0
@pytest.mark.basic
@pytest.mark.install
@pytest.mark.needs_internet
def test_install_does_not_exclude_packaging(pipenv_instance_pypi):
"""Ensure that running `pipenv install` doesn't exclude packaging when its required."""
with pipenv_instance_pypi() as p:
c = p.pipenv("install dataclasses-json")
assert c.returncode == 0
c = p.pipenv(
"""run python -c "from dataclasses_json import DataClassJsonMixin" """
)
assert c.returncode == 0
@pytest.mark.basic
@pytest.mark.install
@pytest.mark.needs_internet
@pytest.mark.skip(
reason="pip 23.3 now vendors in truststore and so test assumptions invalid "
)
def test_install_will_supply_extra_pip_args(pipenv_instance_pypi):
with pipenv_instance_pypi() as p:
c = p.pipenv(
"""install -v dataclasses-json --extra-pip-args="--use-feature=truststore --proxy=test" """
)
assert c.returncode == 1
assert "truststore feature" in c.stdout
@pytest.mark.basic
@pytest.mark.install
@pytest.mark.needs_internet
def test_install_tarball_is_actually_installed(pipenv_instance_pypi):
"""Test case for Issue 5326"""
with pipenv_instance_pypi() as p:
with open(p.pipfile_path, "w") as f:
contents = """
[[source]]
url = "https://pypi.org/simple"
verify_ssl = true
name = "pypi"
[packages]
dataclasses-json = {file = "https://files.pythonhosted.org/packages/85/94/1b30216f84c48b9e0646833f6f2dd75f1169cc04dc45c48fe39e644c89d5/dataclasses-json-0.5.7.tar.gz"}
""".strip()
f.write(contents)
c = p.pipenv("lock")
assert c.returncode == 0
c = p.pipenv("sync")
assert c.returncode == 0
c = p.pipenv("""run python -c "from dataclasses_json import dataclass_json" """)
assert c.returncode == 0
@pytest.mark.basic
@pytest.mark.install
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]
atomicwrites = "*"
colorama = "*"
""".strip()
f.write(contents)
c = p.pipenv("install build")
assert c.returncode == 0
assert "build" in p.pipfile["packages"]
assert list(p.pipfile["packages"].keys()) == ["atomicwrites", "build", "colorama"]
@pytest.mark.basic
@pytest.mark.install
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 = {version = "*"}
parse = "*"
colorama = "*"
atomicwrites = {version = "*"}
""".strip()
f.write(contents)
c = p.pipenv("install build")
assert c.returncode == 0
assert "build" in p.pipfile["packages"]
assert list(p.pipfile["packages"].keys()) == [
"atomicwrites",
"build",
"colorama",
"parse",
"zipp",
]
@pytest.mark.basic
@pytest.mark.install
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]
atomicwrites = "*"
colorama = "*"
""".strip()
f.write(contents)
c = p.pipenv("install build")
assert c.returncode == 0
assert "build" in p.pipfile["packages"]
assert list(p.pipfile["packages"].keys()) == [
"atomicwrites",
"colorama",
"build",
]
@pytest.mark.basic
@pytest.mark.install
def test_category_sorted_with_directive_when_insalling_with_extras(
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]
atomicwrites = "*"
six = "*"
""".strip()
f.write(contents)
c = p.pipenv("install requests[socks]")
assert c.returncode == 0
assert "requests" in p.pipfile["packages"]
assert "extras" in p.pipfile["packages"]["requests"]
assert list(p.pipfile["packages"].keys()) == [
"atomicwrites",
"requests",
"six",
]
@pytest.mark.basic
@pytest.mark.install
def test_install_respects_lockfile_versions(pipenv_instance_pypi):
"""Ensure that `pipenv install` respects versions from existing lockfile."""
with pipenv_instance_pypi() as p:
with open(p.pipfile_path, "w") as f:
contents = """
[[source]]
url = "https://pypi.org/simple"
verify_ssl = true
name = "pypi"
[packages]
sh = "*"
""".strip()
f.write(contents)
with open(p.lockfile_path, "w") as f:
contents = """
{
"_meta": {
"hash": {
"sha256": "f9adf532d46f4787b6afe331abe415d5698ef7523cd6225605328b61f361d427"
},
"pipfile-spec": 6,
"requires": {},
"sources": [
{
"name": "pypi",
"url": "https://pypi.org/simple",
"verify_ssl": true
}
]
},
"default": {
"sh": {
"hashes": [
"sha256:39aa9af22f6558a0c5d132881cf43e34828ca03e4ae11114852ca6a55c7c1d8e",
"sha256:75e86a836f47de095d4531718fe8489e6f7446c75ddfa5596f632727b919ffae"
],
"index": "pypi",
"version": "==1.14.1"
}
},
"develop": {}
}
""".strip()
f.write(contents)
c = p.pipenv("install")
assert c.returncode == 0
# Verify that the locked version is installed, not the latest
c = p.pipenv("graph --json")
assert c.returncode == 0
graph_data = json.loads(c.stdout)
for entry in graph_data:
if entry["package"]["package_name"] == "sh":
assert entry["package"]["installed_version"] == "1.14.1"
break
else:
pytest.fail("sh package not found in graph output")