github.com/containers/libpod@v1.9.4-0.20220419124438-4284fd425507/contrib/cirrus/cirrus_yaml_test.py (about) 1 #!/usr/bin/env python3 2 3 """ 4 Verify contents of .cirrus.yml meet specific expectations 5 """ 6 7 import sys 8 import os 9 import unittest 10 import yaml 11 12 # Assumes directory structure of this file relative to repo. 13 SCRIPT_DIRPATH = os.path.dirname(os.path.realpath(__file__)) 14 REPO_ROOT = os.path.realpath(os.path.join(SCRIPT_DIRPATH, '../', '../')) 15 16 17 class TestCaseBase(unittest.TestCase): 18 19 CIRRUS_YAML = None 20 21 def setUp(self): 22 with open(os.path.join(REPO_ROOT, '.cirrus.yml')) as cirrus_yaml: 23 self.CIRRUS_YAML = yaml.safe_load(cirrus_yaml.read()) 24 25 26 class TestDependsOn(TestCaseBase): 27 28 ALL_TASK_NAMES = None 29 30 def setUp(self): 31 super().setUp() 32 self.ALL_TASK_NAMES = set([key.replace('_task', '') 33 for key, _ in self.CIRRUS_YAML.items() 34 if key.endswith('_task')]) 35 36 def test_00_dicts(self): 37 """Expected dictionaries are present and non-empty""" 38 self.assertIn('success_task', self.CIRRUS_YAML) 39 self.assertIn('success_task'.replace('_task', ''), self.ALL_TASK_NAMES) 40 self.assertIn('depends_on', self.CIRRUS_YAML['success_task']) 41 self.assertGreater(len(self.CIRRUS_YAML['success_task']['depends_on']), 0) 42 43 def test_01_depends(self): 44 """Success task depends on all other tasks""" 45 success_deps = set(self.CIRRUS_YAML['success_task']['depends_on']) 46 for task_name in self.ALL_TASK_NAMES - set(['success']): 47 with self.subTest(task_name=task_name): 48 msg=('Please add "{0}" to the "depends_on" list in "success_task"' 49 "".format(task_name)) 50 self.assertIn(task_name, success_deps, msg=msg) 51 52 53 54 if __name__ == "__main__": 55 unittest.main()