-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathversion_test.py
More file actions
61 lines (41 loc) · 1.91 KB
/
version_test.py
File metadata and controls
61 lines (41 loc) · 1.91 KB
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
# Copyright (c) 2022-2024 Mira Geoscience Ltd. '
# '
# This file is part of surface-apps package. '
# '
# All rights reserved. '
# ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
from __future__ import annotations
import re
from pathlib import Path
import tomli as toml
import yaml
from jinja2 import Template
from packaging.version import Version
import surface_apps
def get_version():
path = Path(__file__).resolve().parents[1] / "pyproject.toml"
with open(str(path), encoding="utf-8") as file:
pyproject = toml.loads(file.read())
return pyproject["tool"]["poetry"]["version"]
def get_conda_recipe_version():
path = Path(__file__).resolve().parents[1] / "recipe.yaml"
with open(str(path), encoding="utf-8") as file:
content = file.read()
template = Template(content)
rendered_yaml = template.render()
recipe = yaml.safe_load(rendered_yaml)
return recipe["context"]["version"]
def test_version_is_consistent():
assert surface_apps.__version__ == get_version()
def test_conda_version_is_pep440():
version = Version(get_conda_recipe_version())
assert version is not None
def test_version_is_semver():
semver_re = (
r"^(?P<major>0|[1-9]\d*)\.(?P<minor>0|[1-9]\d*)\.(?P<patch>0|[1-9]\d*)"
r"(?:-(?P<prerelease>(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)"
r"(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?"
r"(?:\+(?P<buildmetadata>[0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$"
)
assert re.search(semver_re, surface_apps.__version__) is not None