|
| 1 | +"""Tests for --only-binary and --no-binary format control flags. |
| 2 | +
|
| 3 | +These tests verify edge case CLI and requirements file interaction behavior, |
| 4 | +matching the pattern established by --all-releases and --only-final tests. |
| 5 | +""" |
| 6 | + |
| 7 | +from __future__ import annotations |
| 8 | + |
| 9 | +from tests.lib import ( |
| 10 | + PipTestEnvironment, |
| 11 | + create_basic_sdist_for_package, |
| 12 | + create_basic_wheel_for_package, |
| 13 | +) |
| 14 | + |
| 15 | + |
| 16 | +def test_order_no_binary_then_only_binary(script: PipTestEnvironment) -> None: |
| 17 | + """Test --no-binary=:all: --only-binary=<package>. |
| 18 | +
|
| 19 | + When the user specifies --no-binary=:all: --only-binary=simple, they |
| 20 | + expect 'simple' to allow wheels (later flag overrides). |
| 21 | + """ |
| 22 | + wheel_path = create_basic_wheel_for_package(script, "simple", "1.0") |
| 23 | + |
| 24 | + # This should allow wheels for 'simple' because --only-binary comes after |
| 25 | + result = script.pip_install_local( |
| 26 | + "--no-binary=:all:", |
| 27 | + "--only-binary=simple", |
| 28 | + "simple==1.0", |
| 29 | + find_links=[wheel_path.parent], |
| 30 | + ) |
| 31 | + script.assert_installed(simple="1.0") |
| 32 | + # Should NOT be building from source |
| 33 | + assert "Building wheel for simple" not in result.stdout |
| 34 | + |
| 35 | + |
| 36 | +def test_order_only_binary_then_no_binary(script: PipTestEnvironment) -> None: |
| 37 | + """Test --only-binary=:all: --no-binary=<package>. |
| 38 | +
|
| 39 | + When the user specifies --only-binary=:all: --no-binary=simple, |
| 40 | + 'simple' should be built from source (later flag overrides). |
| 41 | + """ |
| 42 | + wheel_path = create_basic_wheel_for_package(script, "simple", "1.0") |
| 43 | + create_basic_sdist_for_package(script, "simple", "1.0") |
| 44 | + |
| 45 | + # This should build from source for 'simple' because --no-binary comes after |
| 46 | + result = script.pip_install_local( |
| 47 | + "--only-binary=:all:", |
| 48 | + "--no-binary=simple", |
| 49 | + "simple==1.0", |
| 50 | + find_links=[wheel_path.parent], |
| 51 | + ) |
| 52 | + script.assert_installed(simple="1.0") |
| 53 | + assert "Building wheel for simple" in result.stdout |
| 54 | + |
| 55 | + |
| 56 | +def test_reqfile_no_binary_overrides_cmdline_only_binary( |
| 57 | + script: PipTestEnvironment, |
| 58 | +) -> None: |
| 59 | + """Test requirements file --no-binary overrides command line --only-binary.""" |
| 60 | + wheel_path = create_basic_wheel_for_package(script, "simple", "1.0") |
| 61 | + create_basic_sdist_for_package(script, "simple", "1.0") |
| 62 | + |
| 63 | + req_file = script.temporary_file( |
| 64 | + "requirements.txt", |
| 65 | + f"--find-links {wheel_path.parent.as_posix()}\n" |
| 66 | + "--no-binary :all:\nsimple==1.0\n", |
| 67 | + ) |
| 68 | + |
| 69 | + result = script.pip_install_local( |
| 70 | + "--only-binary=:all:", "-r", req_file, find_links=[] |
| 71 | + ) |
| 72 | + script.assert_installed(simple="1.0") |
| 73 | + # Requirements file --no-binary should override CLI --only-binary |
| 74 | + assert "Building wheel for simple" in result.stdout |
| 75 | + |
| 76 | + |
| 77 | +def test_reqfile_only_binary_overrides_cmdline_no_binary( |
| 78 | + script: PipTestEnvironment, |
| 79 | +) -> None: |
| 80 | + """Test requirements file --only-binary overrides command line --no-binary.""" |
| 81 | + # Create only a wheel, no sdist |
| 82 | + wheel_path = create_basic_wheel_for_package(script, "simple", "1.0") |
| 83 | + |
| 84 | + req_file = script.temporary_file( |
| 85 | + "requirements.txt", |
| 86 | + f"--find-links {wheel_path.parent.as_posix()}\n" |
| 87 | + "--only-binary :all:\nsimple==1.0\n", |
| 88 | + ) |
| 89 | + |
| 90 | + result = script.pip_install_local( |
| 91 | + "--no-binary=:all:", "-r", req_file, find_links=[] |
| 92 | + ) |
| 93 | + result.assert_installed("simple", editable=False) |
| 94 | + # Requirements file --only-binary should override CLI --no-binary |
| 95 | + assert "Building wheel for simple" not in result.stdout |
| 96 | + |
| 97 | + |
| 98 | +def test_package_specific_overrides_all_in_requirements_file( |
| 99 | + script: PipTestEnvironment, |
| 100 | +) -> None: |
| 101 | + """Test package-specific setting overrides :all: in requirements file.""" |
| 102 | + wheel_path = create_basic_wheel_for_package(script, "simple", "1.0") |
| 103 | + |
| 104 | + req_file = script.temporary_file( |
| 105 | + "requirements.txt", |
| 106 | + f"--find-links {wheel_path.parent.as_posix()}\n--no-binary :all:\n" |
| 107 | + "--only-binary simple\nsimple==1.0\n", |
| 108 | + ) |
| 109 | + |
| 110 | + result = script.pip_install_local("-r", req_file, find_links=[]) |
| 111 | + result.assert_installed("simple", editable=False) |
| 112 | + # Package-specific --only-binary should override --no-binary :all: |
| 113 | + assert "Building wheel for simple" not in result.stdout |
0 commit comments