diff options
Diffstat (limited to 'tests/test_metadata.py')
| -rw-r--r-- | tests/test_metadata.py | 61 |
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 @@ | |||
| 1 | import re | ||
| 2 | import sys | ||
| 3 | |||
| 4 | import toml | ||
| 5 | import adblock | ||
| 6 | |||
| 7 | |||
| 8 | def 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 | |||
| 14 | def 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 | |||
| 33 | def 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 | |||
| 46 | def get_current_python_version(): | ||
| 47 | return f"{sys.version_info.major}.{sys.version_info.minor}.{sys.version_info.micro}" | ||
| 48 | |||
| 49 | |||
| 50 | def 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 | ||
