summaryrefslogtreecommitdiff
path: root/tests
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
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')
-rw-r--r--tests/test_metadata.py61
-rw-r--r--tests/test_version_numbers.py40
2 files changed, 61 insertions, 40 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
diff --git a/tests/test_version_numbers.py b/tests/test_version_numbers.py
deleted file mode 100644
index 77db2f5..0000000
--- a/tests/test_version_numbers.py
+++ /dev/null
@@ -1,40 +0,0 @@
1import subprocess
2
3import toml
4import adblock
5
6
7def get_version_value_poetry():
8 with open("pyproject.toml", encoding="utf-8") as f:
9 pyproject_toml = toml.loads(f.read())
10 return pyproject_toml["tool"]["poetry"]["version"]
11
12
13def get_version_value_cargo():
14 with open("Cargo.toml", encoding="utf-8") as f:
15 cargo_toml = toml.loads(f.read())
16 return cargo_toml["package"]["version"]
17
18
19def get_version_value_changelog():
20 try:
21 proc = subprocess.Popen(["changelog", "current"], stdout=subprocess.PIPE)
22 except FileNotFoundError:
23 return None
24 assert proc.wait() == 0
25 return proc.stdout.read().decode("utf-8").strip()
26
27
28def test_version_numbers_all_same():
29 """
30 Makes sure that `pyproject.toml`, `Cargo.toml`, and `CHANGELOG.md` contain
31 the same version number as the one attached to the `adblock` module.
32 """
33 cargo_version = get_version_value_cargo()
34 poetry_version = get_version_value_poetry()
35 changelog_version = get_version_value_changelog()
36 module_version = adblock.__version__
37
38 assert cargo_version == poetry_version
39 assert poetry_version == module_version
40 assert changelog_version is None or module_version == changelog_version