|
| 1 | +from textwrap import dedent |
| 2 | + |
| 3 | +from pip._vendor import tomli_w |
| 4 | + |
| 5 | +from pip._internal.models.pylock import Pylock |
| 6 | +from pip._internal.utils.compat import tomllib |
| 7 | +from pip._internal.utils.pylock import pylock_to_toml |
| 8 | + |
| 9 | +# This is the PEP 751 example, with a minor modification to the 'environments' |
| 10 | +# field to use double quotes instead of single quotes, since that is what |
| 11 | +# 'packaging' does when serializing markers. |
| 12 | + |
| 13 | +PEP751_EXAMPLE = dedent( |
| 14 | + """\ |
| 15 | + lock-version = '1.0' |
| 16 | + environments = ["sys_platform == \\"win32\\"", "sys_platform == \\"linux\\""] |
| 17 | + requires-python = '==3.12' |
| 18 | + created-by = 'mousebender' |
| 19 | +
|
| 20 | + [[packages]] |
| 21 | + name = 'attrs' |
| 22 | + version = '25.1.0' |
| 23 | + requires-python = '>=3.8' |
| 24 | + wheels = [ |
| 25 | + {name = 'attrs-25.1.0-py3-none-any.whl', upload-time = 2025-01-25T11:30:10.164985+00:00, url = 'https://files.pythonhosted.org/packages/fc/30/d4986a882011f9df997a55e6becd864812ccfcd821d64aac8570ee39f719/attrs-25.1.0-py3-none-any.whl', size = 63152, hashes = {sha256 = 'c75a69e28a550a7e93789579c22aa26b0f5b83b75dc4e08fe092980051e1090a'}}, |
| 26 | + ] |
| 27 | + [[packages.attestation-identities]] |
| 28 | + environment = 'release-pypi' |
| 29 | + kind = 'GitHub' |
| 30 | + repository = 'python-attrs/attrs' |
| 31 | + workflow = 'pypi-package.yml' |
| 32 | +
|
| 33 | + [[packages]] |
| 34 | + name = 'cattrs' |
| 35 | + version = '24.1.2' |
| 36 | + requires-python = '>=3.8' |
| 37 | + dependencies = [ |
| 38 | + {name = 'attrs'}, |
| 39 | + ] |
| 40 | + wheels = [ |
| 41 | + {name = 'cattrs-24.1.2-py3-none-any.whl', upload-time = 2024-09-22T14:58:34.812643+00:00, url = 'https://files.pythonhosted.org/packages/c8/d5/867e75361fc45f6de75fe277dd085627a9db5ebb511a87f27dc1396b5351/cattrs-24.1.2-py3-none-any.whl', size = 66446, hashes = {sha256 = '67c7495b760168d931a10233f979b28dc04daf853b30752246f4f8471c6d68d0'}}, |
| 42 | + ] |
| 43 | +
|
| 44 | + [[packages]] |
| 45 | + name = 'numpy' |
| 46 | + version = '2.2.3' |
| 47 | + requires-python = '>=3.10' |
| 48 | + wheels = [ |
| 49 | + {name = 'numpy-2.2.3-cp312-cp312-win_amd64.whl', upload-time = 2025-02-13T16:51:21.821880+00:00, url = 'https://files.pythonhosted.org/packages/42/6e/55580a538116d16ae7c9aa17d4edd56e83f42126cb1dfe7a684da7925d2c/numpy-2.2.3-cp312-cp312-win_amd64.whl', size = 12626357, hashes = {sha256 = '83807d445817326b4bcdaaaf8e8e9f1753da04341eceec705c001ff342002e5d'}}, |
| 50 | + {name = 'numpy-2.2.3-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl', upload-time = 2025-02-13T16:50:00.079662+00:00, url = 'https://files.pythonhosted.org/packages/39/04/78d2e7402fb479d893953fb78fa7045f7deb635ec095b6b4f0260223091a/numpy-2.2.3-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl', size = 16116679, hashes = {sha256 = '3b787adbf04b0db1967798dba8da1af07e387908ed1553a0d6e74c084d1ceafe'}}, |
| 51 | + ] |
| 52 | +
|
| 53 | + [tool.mousebender] |
| 54 | + command = ['.', 'lock', '--platform', 'cpython3.12-windows-x64', '--platform', 'cpython3.12-manylinux2014-x64', 'cattrs', 'numpy'] |
| 55 | + run-on = 2025-03-06T12:28:57.760769 |
| 56 | + """ # noqa: E501 |
| 57 | +) |
| 58 | + |
| 59 | + |
| 60 | +def test_toml_roundtrip() -> None: |
| 61 | + pylock_dict = tomllib.loads(PEP751_EXAMPLE) |
| 62 | + pylock = Pylock.from_dict(pylock_dict) |
| 63 | + # Check that the roundrip via Pylock dataclasses produces the same toml |
| 64 | + # output, modulo TOML serialization differences. |
| 65 | + assert pylock_to_toml(pylock) == tomli_w.dumps(pylock_dict) |
0 commit comments