From dc33223fcb1583bf31b89474ec299d45d8f80ef0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81rni=20Dagur?= Date: Mon, 1 Feb 2021 17:59:51 +0000 Subject: Packaging improvements (#34) * Use maturin for PEP 517 compliancy * Removing relative import in __init__.py * Bump version to 0.4.2 --- tests/test_metadata.py | 61 +++++++++++++++++++++++++++++++++++++++++++ tests/test_version_numbers.py | 40 ---------------------------- 2 files changed, 61 insertions(+), 40 deletions(-) create mode 100644 tests/test_metadata.py delete mode 100644 tests/test_version_numbers.py (limited to 'tests') 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 @@ +import re +import sys + +import toml +import adblock + + +def get_version_value_cargo(): + with open("Cargo.toml", encoding="utf-8") as f: + cargo_toml = toml.loads(f.read()) + return cargo_toml["package"]["version"] + + +def get_version_value_changelog(): + """ + Try to get the names of all classes that we added to the Python module + from Rust. As always, we unfortunately don't have access to the Rust AST + so we have to make do with regular expressions. + """ + versions = [] + with open("CHANGELOG.md", "r", encoding="utf-8") as f: + for line in f: + match = re.match( + r"## ([0-9]+\.[0-9]+\.[0-9]+) - \(20[0-9]+-[0-1][0-9]-[0-3][0-9]\)", + line.strip(), + ) + if match is not None: + versions.append(match.group(1)) + assert versions == sorted(versions, reverse=True) + return versions[0] + + +def test_version_numbers_all_same(): + """ + Makes sure that `Cargo.toml` and `CHANGELOG.md` contain the same version + number as the one attached to the `adblock` module. + """ + cargo_version = get_version_value_cargo() + changelog_version = get_version_value_changelog() + module_version = adblock.__version__ + + assert cargo_version == module_version + assert module_version == changelog_version + + +def get_current_python_version(): + return f"{sys.version_info.major}.{sys.version_info.minor}.{sys.version_info.micro}" + + +def test_required_python_version(): + """ + Make sure that the Python interpreter we're running this test suite on + falls into the required Python range. + """ + with open("Cargo.toml", encoding="utf-8") as f: + cargo_toml = toml.loads(f.read()) + + required_python = cargo_toml["package"]["metadata"]["maturin"]["requires-python"] + assert required_python.startswith(">=") + required_python = required_python[2:] + 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 @@ -import subprocess - -import toml -import adblock - - -def get_version_value_poetry(): - with open("pyproject.toml", encoding="utf-8") as f: - pyproject_toml = toml.loads(f.read()) - return pyproject_toml["tool"]["poetry"]["version"] - - -def get_version_value_cargo(): - with open("Cargo.toml", encoding="utf-8") as f: - cargo_toml = toml.loads(f.read()) - return cargo_toml["package"]["version"] - - -def get_version_value_changelog(): - try: - proc = subprocess.Popen(["changelog", "current"], stdout=subprocess.PIPE) - except FileNotFoundError: - return None - assert proc.wait() == 0 - return proc.stdout.read().decode("utf-8").strip() - - -def test_version_numbers_all_same(): - """ - Makes sure that `pyproject.toml`, `Cargo.toml`, and `CHANGELOG.md` contain - the same version number as the one attached to the `adblock` module. - """ - cargo_version = get_version_value_cargo() - poetry_version = get_version_value_poetry() - changelog_version = get_version_value_changelog() - module_version = adblock.__version__ - - assert cargo_version == poetry_version - assert poetry_version == module_version - assert changelog_version is None or module_version == changelog_version -- cgit v1.2.3