github.com/hanks177/podman/v4@v4.1.3-0.20220613032544-16d90015bc83/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 SUCCESS_DEPS_EXCLUDE = set(['success', 'artifacts', 30 'test_image_build', 'release', 'release_test']) 31 32 def setUp(self): 33 super().setUp() 34 self.ALL_TASK_NAMES = set([key.replace('_task', '') 35 for key, _ in self.CIRRUS_YAML.items() 36 if key.endswith('_task')]) 37 38 def test_dicts(self): 39 """Expected dictionaries are present and non-empty""" 40 self.assertIn('success_task', self.CIRRUS_YAML) 41 self.assertIn('success_task'.replace('_task', ''), self.ALL_TASK_NAMES) 42 self.assertIn('depends_on', self.CIRRUS_YAML['success_task']) 43 self.assertGreater(len(self.CIRRUS_YAML['success_task']['depends_on']), 0) 44 45 def test_task(self): 46 """There is no task named 'task'""" 47 self.assertNotIn('task', self.ALL_TASK_NAMES) 48 49 def test_depends(self): 50 """Success task depends on all other tasks""" 51 success_deps = set(self.CIRRUS_YAML['success_task']['depends_on']) 52 for task_name in self.ALL_TASK_NAMES - self.SUCCESS_DEPS_EXCLUDE: 53 with self.subTest(task_name=task_name): 54 msg=('Please add "{0}" to the "depends_on" list in "success_task"' 55 "".format(task_name)) 56 self.assertIn(task_name, success_deps, msg=msg) 57 58 def not_task(self): 59 """Ensure no task is named 'task'""" 60 self.assertNotIn('task', self.ALL_TASK_NAMES) 61 62 if __name__ == "__main__": 63 unittest.main()