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