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
|
# Copyright (c) 2022 Chris Richardson, Garth Wells and Jack S. Hale
# FEniCS Project
# SPDX-License-Identifier: MIT
import re
from importlib.metadata import version
import pytest
import basix
def is_canonical(version):
"""Check version number is canonical according to PEP0440
From https://peps.python.org/pep-0440/#appendix-b-parsing-version-strings-with-regular-expressions"""
return (
re.match(
r"^([1-9][0-9]*!)?(0|[1-9][0-9]*)(\.(0|[1-9][0-9]*))*((a|b|rc)(0|[1-9][0-9]*))?(\.post(0|[1-9][0-9]*))?(\.dev(0|[1-9][0-9]*))?$",
version,
)
is not None
)
def test_version(python_version=version("fenics-basix"), cpp_version=basix.__version__):
assert is_canonical(python_version)
# Strip Python-specific versioning (dev, post) and compare with C++
# versioning
stripped_version = re.sub(r"(\.post(0|[1-9][0-9]*))", "", python_version)
stripped_version = stripped_version.replace("dev", "")
if stripped_version != cpp_version:
raise RuntimeError(
f"The version numbers of the Python ({python_version} "
f"-> {stripped_version}) and nanobind/C++ ({basix.__version__}) "
" libraries do not match."
)
def test_test_version_logic():
with pytest.raises(RuntimeError):
test_version("0.4.2.dev0", "0.4.2")
test_version("0.4.2.post0", "0.4.2")
test_version("0.4.2.dev0", "0.4.2.0")
|