Archived
Use English source strings wrapped for gettext, ship a German catalogue, and check that README and package metadata match the PluginConfig. Co-Authored-By: Claude Opus 5.5 <[email protected]>
58 lines
2.1 KiB
Python
58 lines
2.1 KiB
Python
"""Keep README and packaging metadata in sync with the PluginConfig.
|
||
|
||
Runs without NetBox: `python -m unittest discover -s tests`.
|
||
"""
|
||
import ast
|
||
import re
|
||
import tomllib
|
||
import unittest
|
||
from pathlib import Path
|
||
|
||
ROOT = Path(__file__).resolve().parents[1]
|
||
|
||
|
||
def plugin_config():
|
||
tree = ast.parse((ROOT / "netbox_better_ips" / "__init__.py").read_text())
|
||
return {
|
||
node.targets[0].id: node.value.value
|
||
for node in ast.walk(tree)
|
||
if isinstance(node, ast.Assign)
|
||
and isinstance(node.targets[0], ast.Name)
|
||
and isinstance(node.value, ast.Constant)
|
||
}
|
||
|
||
|
||
def readme_range(max_version):
|
||
# max_version "4.7.99" is written as "4.7.x" in the README
|
||
major_minor, patch = max_version.rsplit(".", 1)
|
||
return major_minor + ".x" if patch == "99" else max_version
|
||
|
||
|
||
class MetadataTest(unittest.TestCase):
|
||
def setUp(self):
|
||
self.config = plugin_config()
|
||
self.readme = (ROOT / "README.md").read_text()
|
||
|
||
def test_readme_netbox_range_matches_plugin_config(self):
|
||
expected = f"`{self.config['min_version']}` – `{readme_range(self.config['max_version'])}`"
|
||
info_row = re.search(r"^\| \*\*NetBox\*\* \| (.+?) \|$", self.readme, re.M)
|
||
self.assertIsNotNone(info_row, "README info table has no NetBox row")
|
||
self.assertEqual(info_row.group(1), expected)
|
||
compatibility = self.readme.split("## Compatibility", 1)[1].split("\n## ", 1)[0]
|
||
self.assertIn(f"NetBox {expected}", compatibility)
|
||
|
||
def test_package_version_matches_plugin_config(self):
|
||
project = tomllib.loads((ROOT / "pyproject.toml").read_text())["project"]
|
||
self.assertEqual(project["version"], self.config["__version__"])
|
||
|
||
def test_translations_are_shipped(self):
|
||
package_data = tomllib.loads((ROOT / "pyproject.toml").read_text())["tool"]["setuptools"][
|
||
"package-data"
|
||
]["netbox_better_ips"]
|
||
self.assertIn("locale/*/LC_MESSAGES/*.mo", package_data)
|
||
self.assertTrue((ROOT / "netbox_better_ips/locale/de/LC_MESSAGES/django.mo").is_file())
|
||
|
||
|
||
if __name__ == "__main__":
|
||
unittest.main()
|