forked from overhangio/tpi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tests.py
53 lines (43 loc) · 1.83 KB
/
tests.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
from __future__ import annotations
import os
import typing as t
import unittest
import yaml
ROOT_DIR = os.path.dirname(__file__)
RELEASES = os.listdir(os.path.join(ROOT_DIR, "main"))
INDEXES = ["main", "contrib"]
class IndexTests(unittest.TestCase):
def test_releases_exist(self) -> None:
for release in RELEASES:
for index in INDEXES:
path = index_path(release, index)
self.assertTrue(os.path.isfile(path), f"Missing index: {path}")
def test_names_are_unique(self) -> None:
for release in RELEASES:
names: t.Set[str] = set()
for index in INDEXES:
for plugin in load_index(release, index):
self.assertNotIn(
plugin["name"],
names,
f"Duplicate plugin name '{plugin['name']}' found in release {release}",
)
names.add(plugin["name"])
def test_all_plugins_have_all_fields(self) -> None:
required_fields = ["src", "url", "author", "maintainer", "description"]
for release in RELEASES:
for index in INDEXES:
for plugin in load_index(release, index):
for field in required_fields:
self.assertIn(field, plugin)
self.assertTrue(
plugin[field] and plugin[field].strip(),
f"Field {field} cannot be empty",
)
def load_index(release: str, index: str) -> list[dict[str, str]]:
with open(index_path(release, index), encoding="utf8") as f:
index = yaml.safe_load(f)
assert isinstance(index, list)
return index
def index_path(release: str, index: str) -> str:
return os.path.join(ROOT_DIR, index, release, "plugins.yml")