tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

test_util_runnable_jobs.py (2162B)


      1 # This Source Code Form is subject to the terms of the Mozilla Public
      2 # License, v. 2.0. If a copy of the MPL was not distributed with this
      3 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
      4 
      5 
      6 import unittest
      7 
      8 from mozunit import main
      9 from taskgraph.graph import Graph
     10 from taskgraph.task import Task
     11 from taskgraph.taskgraph import TaskGraph
     12 
     13 from gecko_taskgraph.decision import full_task_graph_to_runnable_jobs
     14 
     15 
     16 class TestRunnableJobs(unittest.TestCase):
     17    tasks = [
     18        {
     19            "kind": "build",
     20            "label": "a",
     21            "attributes": {},
     22            "task": {
     23                "extra": {"treeherder": {"symbol": "B"}},
     24            },
     25        },
     26        {
     27            "kind": "test",
     28            "label": "b",
     29            "attributes": {},
     30            "task": {
     31                "extra": {
     32                    "treeherder": {
     33                        "collection": {"opt": True},
     34                        "groupName": "Some group",
     35                        "groupSymbol": "GS",
     36                        "machine": {"platform": "linux64"},
     37                        "symbol": "t",
     38                    }
     39                },
     40            },
     41        },
     42    ]
     43 
     44    def make_taskgraph(self, tasks):
     45        label_to_taskid = {k: k + "-tid" for k in tasks}
     46        for label, task_id in label_to_taskid.items():
     47            tasks[label].task_id = task_id
     48        graph = Graph(nodes=set(tasks), edges=set())
     49        taskgraph = TaskGraph(tasks, graph)
     50        return taskgraph, label_to_taskid
     51 
     52    def test_taskgraph_to_runnable_jobs(self):
     53        tg, label_to_taskid = self.make_taskgraph({
     54            t["label"]: Task(**t) for t in self.tasks[:]
     55        })
     56 
     57        res = full_task_graph_to_runnable_jobs(tg.to_json())
     58 
     59        self.assertEqual(
     60            res,
     61            {
     62                "a": {"symbol": "B"},
     63                "b": {
     64                    "collection": {"opt": True},
     65                    "groupName": "Some group",
     66                    "groupSymbol": "GS",
     67                    "symbol": "t",
     68                    "platform": "linux64",
     69                },
     70            },
     71        )
     72 
     73 
     74 if __name__ == "__main__":
     75    main()