2022-10-21 12:08:18 +02:00
|
|
|
import os
|
|
|
|
import unittest
|
|
|
|
|
|
|
|
import yaml
|
|
|
|
|
|
|
|
from lib.db import DB
|
|
|
|
from lib.db_revision import DBRevision
|
2022-10-22 12:03:21 +02:00
|
|
|
from lib.tree_builder import TreeBuilder
|
2022-10-21 12:08:18 +02:00
|
|
|
|
|
|
|
|
|
|
|
class TestTreeMethods(unittest.TestCase):
|
|
|
|
def setUp(self):
|
|
|
|
self.db = DB(section="test")
|
2022-10-27 15:15:23 +02:00
|
|
|
|
|
|
|
def verify_package(self, package):
|
|
|
|
path = os.path.join(os.path.dirname(__file__), f"fixtures/{package}-data.yaml")
|
2022-10-21 12:08:18 +02:00
|
|
|
with open(path, "r") as f:
|
2022-10-27 15:15:23 +02:00
|
|
|
data = yaml.safe_load(f)
|
|
|
|
for rev in data["revisions"]:
|
2022-10-21 12:08:18 +02:00
|
|
|
DBRevision.import_fixture_dict(self.db, rev)
|
|
|
|
|
2022-11-02 08:50:54 +01:00
|
|
|
revisions = TreeBuilder(self.db).build("openSUSE:Factory", package)
|
2022-10-27 13:16:50 +02:00
|
|
|
path = os.path.join(
|
2022-10-27 15:15:23 +02:00
|
|
|
os.path.dirname(__file__), f"fixtures/{package}-expected-tree.yaml"
|
2022-10-27 13:16:50 +02:00
|
|
|
)
|
2022-10-27 15:15:23 +02:00
|
|
|
# REGENERATE_DATA=1 PYTHONPATH=$PWD python3 ./tests/tree_test.py
|
|
|
|
if os.getenv("REGENERATE_DATA"):
|
|
|
|
with open(path, "w") as f:
|
|
|
|
yaml.dump(revisions.as_list(), f)
|
|
|
|
|
2022-10-27 13:16:50 +02:00
|
|
|
with open(path, "r") as f:
|
2022-10-27 15:15:23 +02:00
|
|
|
data = yaml.safe_load(f)
|
|
|
|
self.assertEqual(data, revisions.as_list())
|
2022-11-02 07:20:53 +01:00
|
|
|
|
|
|
|
# verify flat lists
|
|
|
|
path = os.path.join(
|
|
|
|
os.path.dirname(__file__), f"fixtures/{package}-expected-list.yaml"
|
|
|
|
)
|
|
|
|
flat_list = [str(x) for x in revisions.as_flat_list()]
|
|
|
|
if os.getenv("REGENERATE_DATA"):
|
|
|
|
with open(path, "w") as f:
|
|
|
|
yaml.dump(flat_list, f)
|
|
|
|
|
|
|
|
with open(path, "r") as f:
|
|
|
|
data = yaml.safe_load(f)
|
|
|
|
self.assertEqual(data, flat_list)
|
|
|
|
|
2022-10-27 15:15:23 +02:00
|
|
|
self.db.conn.rollback()
|
|
|
|
|
|
|
|
def test_zsh_tree(self):
|
|
|
|
self.verify_package("zsh")
|
|
|
|
|
|
|
|
def test_clapper_tree(self):
|
|
|
|
self.verify_package("clapper")
|
2022-10-21 12:08:18 +02:00
|
|
|
|
2022-11-01 11:45:20 +01:00
|
|
|
def test_llvm13_tree(self):
|
|
|
|
self.verify_package("llvm13")
|
2022-10-21 12:08:18 +02:00
|
|
|
|
2022-11-01 18:44:59 +01:00
|
|
|
def test_2048_cli_tree(self):
|
|
|
|
self.verify_package("2048-cli")
|
2022-11-01 13:09:27 +01:00
|
|
|
|
2022-11-01 18:58:27 +01:00
|
|
|
def test_corefreq_tree(self):
|
|
|
|
self.verify_package("CoreFreq")
|
|
|
|
|
2022-11-01 19:30:41 +01:00
|
|
|
def test_000update_repos_tree(self):
|
|
|
|
self.verify_package("000update-repos")
|
|
|
|
|
2022-11-03 09:47:53 +01:00
|
|
|
def test_breeze_tree(self):
|
|
|
|
self.verify_package("breeze")
|
|
|
|
|
2022-11-03 12:35:03 +01:00
|
|
|
def test_firewalld_tree(self):
|
|
|
|
self.verify_package("firewalld")
|
2022-11-01 18:58:27 +01:00
|
|
|
|
2022-11-03 15:03:41 +01:00
|
|
|
|
2022-10-21 12:08:18 +02:00
|
|
|
if __name__ == "__main__":
|
|
|
|
unittest.main()
|