summaryrefslogtreecommitdiff
path: root/tests/test_metadata.py
diff options
context:
space:
mode:
authorÁrni Dagur <arni@dagur.eu>2021-02-01 17:59:51 +0000
committerGitHub <noreply@github.com>2021-02-01 17:59:51 +0000
commitdc33223fcb1583bf31b89474ec299d45d8f80ef0 (patch)
treef3c0e12505f3191c20e959fe3e81da445a28c59f /tests/test_metadata.py
parentd0dbf823b7ce627ee77067cd87188fa9995ad783 (diff)
Packaging improvements (#34)
* Use maturin for PEP 517 compliancy * Removing relative import in __init__.py * Bump version to 0.4.2
Diffstat (limited to 'tests/test_metadata.py')
-rw-r--r--tests/test_metadata.py61
1 files changed, 61 insertions, 0 deletions
diff --git a/tests/test_metadata.py b/tests/test_metadata.py
new file mode 100644
index 0000000..1a0e6d8
--- /dev/null
+++ b/tests/test_metadata.py
@@ -0,0 +1,61 @@
1import re
2import sys
3
4import toml
5import adblock
6
7
8def get_version_value_cargo():
9 with open("Cargo.toml", encoding="utf-8") as f:
10 cargo_toml = toml.loads(f.read())
11 return cargo_toml["package"]["version"]
12
13
14def get_version_value_changelog():
15 """
16 Try to get the names of all classes that we added to the Python module
17 from Rust. As always, we unfortunately don't have access to the Rust AST
18 so we have to make do with regular expressions.
19 """
20 versions = []
21 with open("CHANGELOG.md", "r", encoding="utf-8") as f:
22 for line in f:
23 match = re.match(
24 r"## ([0-9]+\.[0-9]+\.[0-9]+) - \(20[0-9]+-[0-1][0-9]-[0-3][0-9]\)",
25 line.strip(),
26 )
27 if match is not None:
28 versions.append(match.group(1))
29 assert versions == sorted(versions, reverse=True)
30 return versions[0]
31
32
33def test_version_numbers_all_same():
34 """
35 Makes sure that `Cargo.toml` and `CHANGELOG.md` contain the same version
36 number as the one attached to the `adblock` module.
37 """
38 cargo_version = get_version_value_cargo()
39 changelog_version = get_version_value_changelog()
40 module_version = adblock.__version__
41
42 assert cargo_version == module_version
43 assert module_version == changelog_version
44
45
46def get_current_python_version():
47 return f"{sys.version_info.major}.{sys.version_info.minor}.{sys.version_info.micro}"
48
49
50def test_required_python_version():
51 """
52 Make sure that the Python interpreter we're running this test suite on
53 falls into the required Python range.
54 """
55 with open("Cargo.toml", encoding="utf-8") as f:
56 cargo_toml = toml.loads(f.read())
57
58 required_python = cargo_toml["package"]["metadata"]["maturin"]["requires-python"]
59 assert required_python.startswith(">=")
60 required_python = required_python[2:]
61 assert get_current_python_version() >= required_python