Files
cibuildwheel/unit_test/build_ids_test.py
T
Shantanuandhauntsaninja <> 6d4431306e chore: use tomllib on Python 3.11 (#1047)
* Use tomllib on Python 3.11

* delint

Co-authored-by: hauntsaninja <>
2022-04-16 00:00:57 -04:00

50 lines
1.3 KiB
Python

import sys
from typing import Dict, List
if sys.version_info >= (3, 11):
import tomllib
else:
import tomli as tomllib
from packaging.version import Version
from cibuildwheel.extra import Printable, dump_python_configurations
from cibuildwheel.util import resources_dir
def test_compare_configs():
with open(resources_dir / "build-platforms.toml") as f1:
txt = f1.read()
with open(resources_dir / "build-platforms.toml", "rb") as f2:
dict_txt = tomllib.load(f2)
new_txt = dump_python_configurations(dict_txt)
print(new_txt)
assert new_txt == txt
def test_dump_with_Version():
# MyPy doesn't understand deeply nested dicts correctly
example: Dict[str, Dict[str, List[Dict[str, Printable]]]] = {
"windows": {
"python_configurations": [
{"identifier": "cp27-win32", "version": Version("2.7.18"), "arch": "32"},
{"identifier": "cp27-win_amd64", "version": "2.7.18", "arch": "64"},
]
}
}
result = """\
[windows]
python_configurations = [
{ identifier = "cp27-win32", version = "2.7.18", arch = "32" },
{ identifier = "cp27-win_amd64", version = "2.7.18", arch = "64" },
]
"""
output = dump_python_configurations(example)
print(output)
assert output == result