Bug 1286075: refactor test.py to use TransformTask; r=gps draft
authorDustin J. Mitchell <dustin@mozilla.com>
Fri, 29 Jul 2016 22:31:22 +0000
changeset 412715 26c16cb14bb9f7bb90cbea717222f86b07af37d3
parent 412714 1890bcf94059a3ffd6d8fd1613e3be48d502f27c
child 412716 a2bcef79cdda65630762d322e0c1897ca0f2cd3d
push id29252
push userdmitchell@mozilla.com
push dateMon, 12 Sep 2016 19:16:39 +0000
reviewersgps
bugs1286075
milestone51.0a1
Bug 1286075: refactor test.py to use TransformTask; r=gps MozReview-Commit-ID: 1H0P4mkzijG
taskcluster/taskgraph/task/test.py
--- a/taskcluster/taskgraph/task/test.py
+++ b/taskcluster/taskgraph/task/test.py
@@ -4,30 +4,28 @@
 
 from __future__ import absolute_import, print_function, unicode_literals
 
 import copy
 import logging
 import os
 import yaml
 
-from . import base
-from taskgraph.util.python_path import find_object
-from taskgraph.transforms.base import TransformSequence, TransformConfig
+from . import transform
 
 logger = logging.getLogger(__name__)
 
 
-class TestTask(base.Task):
+class TestTask(transform.TransformTask):
     """
     A task implementing a Gecko test.
     """
 
     @classmethod
-    def load_tasks(cls, kind, path, config, params, loaded_tasks):
+    def get_inputs(cls, kind, path, config, params, loaded_tasks):
 
         # the kind on which this one depends
         if len(config.get('kind-dependencies', [])) != 1:
             raise Exception("TestTask kinds must have exactly one item in kind-dependencies")
         dep_kind = config['kind-dependencies'][0]
 
         # get build tasks, keyed by build platform
         builds_by_platform = cls.get_builds_by_platform(dep_kind, loaded_tasks)
@@ -38,43 +36,28 @@ class TestTask(base.Task):
 
         # expand the test sets for each of those platforms
         test_sets_cfg = load_yaml(path, 'test-sets.yml')
         test_platforms = cls.expand_tests(test_sets_cfg, test_platforms)
 
         # load the test descriptions
         test_descriptions = load_yaml(path, 'tests.yml')
 
-        # load the transformation functions
-        transforms = cls.load_transforms(config['transforms'])
-
         # generate all tests for all test platforms
-        def tests():
-            for test_platform_name, test_platform in test_platforms.iteritems():
-                for test_name in test_platform['test-names']:
-                    test = copy.deepcopy(test_descriptions[test_name])
-                    test['build-platform'] = test_platform['build-platform']
-                    test['test-platform'] = test_platform_name
-                    test['build-label'] = test_platform['build-label']
-                    test['test-name'] = test_name
-                    yield test
+        for test_platform_name, test_platform in test_platforms.iteritems():
+            for test_name in test_platform['test-names']:
+                test = copy.deepcopy(test_descriptions[test_name])
+                test['build-platform'] = test_platform['build-platform']
+                test['test-platform'] = test_platform_name
+                test['build-label'] = test_platform['build-label']
+                test['test-name'] = test_name
 
-        # log each source test definition as it is created; this helps when debugging
-        # an exception in task generation
-        def log_tests(config, tests):
-            for test in tests:
                 logger.debug("Generating tasks for {} test {} on platform {}".format(
-                    kind, test['test-name'], test['test-platform']))
+                    kind, test_name, test['test-platform']))
                 yield test
-        transforms = TransformSequence([log_tests] + transforms)
-
-        # perform the transformations
-        config = TransformConfig(kind, path, config, params)
-        tasks = [cls(config.kind, t) for t in transforms(config, tests())]
-        return tasks
 
     @classmethod
     def get_builds_by_platform(cls, dep_kind, loaded_tasks):
         """Find the build tasks on which tests will depend, keyed by
         platform/type.  Returns a dictionary mapping build platform to task
         label."""
         builds_by_platform = {}
         for task in loaded_tasks:
@@ -127,39 +110,14 @@ class TestTask(base.Task):
                 raise Exception(
                     "Test set '{}' for test platform {} is not defined".format(
                         test_set, test_platform))
             test_names = test_sets_cfg[test_set]
             rv[test_platform] = cfg.copy()
             rv[test_platform]['test-names'] = test_names
         return rv
 
-    @classmethod
-    def load_transforms(cls, transforms_cfg):
-        """Load the transforms specified in kind.yml"""
-        transforms = []
-        for path in transforms_cfg:
-            transform = find_object(path)
-            transforms.append(transform)
-        return transforms
-
-    @classmethod
-    def from_json(cls, task_dict):
-        test_task = cls(kind=task_dict['attributes']['kind'],
-                        task=task_dict)
-        return test_task
-
-    def __init__(self, kind, task):
-        self.dependencies = task['dependencies']
-        super(TestTask, self).__init__(kind, task['label'], task['attributes'], task['task'])
-
-    def get_dependencies(self, taskgraph):
-        return [(label, name) for name, label in self.dependencies.items()]
-
-    def optimize(self):
-        return False, None
-
 
 def load_yaml(path, name):
     """Convenience method to load a YAML file in the kind directory"""
     filename = os.path.join(path, name)
     with open(filename, "rb") as f:
         return yaml.load(f)