|
| 1 | +from wheel.cli.tags import tags |
| 2 | +import os |
| 3 | +import py |
| 4 | +import pytest |
| 5 | + |
| 6 | +from wheel.wheelfile import WheelFile |
| 7 | +from wheel.cli import parser |
| 8 | + |
| 9 | +THISDIR = os.path.dirname(__file__) |
| 10 | +TESTWHEEL_NAME = 'test-1.0-py2.py3-none-any.whl' |
| 11 | +TESTWHEEL_PATH = os.path.join(THISDIR, '..', 'testdata', TESTWHEEL_NAME) |
| 12 | + |
| 13 | + |
| 14 | +@pytest.fixture |
| 15 | +def wheelpath(tmpdir): |
| 16 | + fn = tmpdir.mkdir("wheels").join(TESTWHEEL_NAME) |
| 17 | + py.path.local(TESTWHEEL_PATH).copy(fn) |
| 18 | + return fn |
| 19 | + |
| 20 | + |
| 21 | +def test_tags_no_args(wheelpath): |
| 22 | + (newname,) = tags([str(wheelpath)]) |
| 23 | + assert TESTWHEEL_NAME == newname |
| 24 | + assert wheelpath.exists() |
| 25 | + |
| 26 | + |
| 27 | +def test_python_tags(wheelpath): |
| 28 | + (newname,) = tags([str(wheelpath)], python_tags=['py3']) |
| 29 | + assert TESTWHEEL_NAME.replace('py2.py3', 'py3') == newname |
| 30 | + output_file = wheelpath.dirpath(newname) |
| 31 | + with WheelFile(str(output_file)) as f: |
| 32 | + output = f.read(f.dist_info_path + '/WHEEL') |
| 33 | + assert ( |
| 34 | + output |
| 35 | + == b'Wheel-Version: 1.0\r\nGenerator: bdist_wheel (0.30.0)' |
| 36 | + b'\r\nRoot-Is-Purelib: false\r\nTag: py3-none-any\r\n' |
| 37 | + ) |
| 38 | + output_file.remove() |
| 39 | + |
| 40 | + (newname,) = tags([str(wheelpath)], python_tags=['py2.py3']) |
| 41 | + assert TESTWHEEL_NAME == newname |
| 42 | + |
| 43 | + (newname,) = tags([str(wheelpath)], python_tags=['', 'py4'], remove=True) |
| 44 | + assert not wheelpath.exists() |
| 45 | + assert TESTWHEEL_NAME.replace('py2.py3', 'py2.py3.py4') == newname |
| 46 | + output_file = wheelpath.dirpath(newname) |
| 47 | + output_file.remove() |
| 48 | + |
| 49 | + |
| 50 | +def test_abi_tags(wheelpath): |
| 51 | + (newname,) = tags([str(wheelpath)], abi_tags=['cp33m']) |
| 52 | + assert TESTWHEEL_NAME.replace('none', 'cp33m') == newname |
| 53 | + output_file = wheelpath.dirpath(newname) |
| 54 | + output_file.remove() |
| 55 | + |
| 56 | + (newname,) = tags([str(wheelpath)], abi_tags=['abi3', 'cp33m']) |
| 57 | + assert TESTWHEEL_NAME.replace('none', 'abi3.cp33m') == newname |
| 58 | + output_file = wheelpath.dirpath(newname) |
| 59 | + output_file.remove() |
| 60 | + |
| 61 | + (newname,) = tags([str(wheelpath)], abi_tags=['none']) |
| 62 | + assert TESTWHEEL_NAME == newname |
| 63 | + |
| 64 | + (newname,) = tags([str(wheelpath)], abi_tags=['', 'abi3', 'cp33m'], remove=True) |
| 65 | + assert not wheelpath.exists() |
| 66 | + assert TESTWHEEL_NAME.replace('none', 'abi3.cp33m.none') == newname |
| 67 | + output_file = wheelpath.dirpath(newname) |
| 68 | + output_file.remove() |
| 69 | + |
| 70 | + |
| 71 | +def test_plat_tags(wheelpath): |
| 72 | + (newname,) = tags([str(wheelpath)], platform_tags=['linux_x86_64']) |
| 73 | + assert TESTWHEEL_NAME.replace('any', 'linux_x86_64') == newname |
| 74 | + output_file = wheelpath.dirpath(newname) |
| 75 | + assert output_file.exists() |
| 76 | + output_file.remove() |
| 77 | + |
| 78 | + (newname,) = tags([str(wheelpath)], platform_tags=['linux_x86_64', 'win32']) |
| 79 | + assert TESTWHEEL_NAME.replace('any', 'linux_x86_64.win32') == newname |
| 80 | + output_file = wheelpath.dirpath(newname) |
| 81 | + assert output_file.exists() |
| 82 | + output_file.remove() |
| 83 | + |
| 84 | + (newname,) = tags([str(wheelpath)], platform_tags=['', 'linux_x86_64', 'win32']) |
| 85 | + assert TESTWHEEL_NAME.replace('any', 'any.linux_x86_64.win32') == newname |
| 86 | + output_file = wheelpath.dirpath(newname) |
| 87 | + assert output_file.exists() |
| 88 | + output_file.remove() |
| 89 | + |
| 90 | + (newname,) = tags([str(wheelpath)], platform_tags=['any']) |
| 91 | + assert TESTWHEEL_NAME == newname |
| 92 | + |
| 93 | + |
| 94 | +def test_build_number(wheelpath): |
| 95 | + (newname,) = tags([str(wheelpath)], build_number=1) |
| 96 | + assert TESTWHEEL_NAME.replace('-py2', '-1-py2') == newname |
| 97 | + output_file = wheelpath.dirpath(newname) |
| 98 | + assert output_file.exists() |
| 99 | + output_file.remove() |
| 100 | + |
| 101 | + |
| 102 | +def test_multi_tags(wheelpath): |
| 103 | + (newname,) = tags( |
| 104 | + [str(wheelpath)], |
| 105 | + platform_tags=['linux_x86_64'], |
| 106 | + python_tags=['', 'py4'], |
| 107 | + build_number=1, |
| 108 | + ) |
| 109 | + assert 'test-1.0-1-py2.py3.py4-none-linux_x86_64.whl' == newname |
| 110 | + |
| 111 | + output_file = wheelpath.dirpath(newname) |
| 112 | + assert output_file.exists() |
| 113 | + with WheelFile(str(output_file)) as f: |
| 114 | + output = f.read(f.dist_info_path + '/WHEEL') |
| 115 | + assert ( |
| 116 | + output |
| 117 | + == b'Wheel-Version: 1.0\r\nGenerator: bdist_wheel (0.30.0)\r\nRoot-Is-Purelib:' |
| 118 | + b' false\r\nTag: py2-none-linux_x86_64\r\nTag: py3-none-linux_x86_64\r\nTag:' |
| 119 | + b' py4-none-linux_x86_64\r\nBuild: 1\r\n' |
| 120 | + ) |
| 121 | + output_file.remove() |
| 122 | + |
| 123 | + |
| 124 | +def test_tags_command(capsys, wheelpath): |
| 125 | + args = [ |
| 126 | + 'tags', |
| 127 | + '--python-tag', 'py3', |
| 128 | + '--abi-tag', 'cp33m', |
| 129 | + '--platform-tag', 'linux_x86_64', |
| 130 | + '--build', '7', |
| 131 | + str(wheelpath), |
| 132 | + ] |
| 133 | + p = parser() |
| 134 | + args = p.parse_args(args) |
| 135 | + args.func(args) |
| 136 | + assert wheelpath.exists() |
| 137 | + |
| 138 | + newname = capsys.readouterr().out.strip() |
| 139 | + assert 'test-1.0-7-py3-cp33m-linux_x86_64.whl' == newname |
| 140 | + output_file = wheelpath.dirpath(newname) |
| 141 | + output_file.remove() |
| 142 | + |
| 143 | + |
| 144 | +def test_tags_command_del(capsys, wheelpath): |
| 145 | + args = [ |
| 146 | + 'tags', |
| 147 | + '--python-tag', '.py4', |
| 148 | + '--abi-tag', 'cp33m', |
| 149 | + '--platform-tag', 'linux_x86_64', |
| 150 | + '--remove', |
| 151 | + str(wheelpath), |
| 152 | + ] |
| 153 | + p = parser() |
| 154 | + args = p.parse_args(args) |
| 155 | + args.func(args) |
| 156 | + assert not wheelpath.exists() |
| 157 | + |
| 158 | + newname = capsys.readouterr().out.strip() |
| 159 | + assert 'test-1.0-py2.py3.py4-cp33m-linux_x86_64.whl' == newname |
| 160 | + output_file = wheelpath.dirpath(newname) |
| 161 | + output_file.remove() |
0 commit comments