From ffd94e2849cc2600afc196829e578ffeb987d9c5 Mon Sep 17 00:00:00 2001 From: Simon Sapin Date: Fri, 21 Sep 2018 15:10:42 +0200 Subject: [PATCH] Add decision task mocking --- etc/ci/taskcluster/decisionlib.py | 2 +- etc/ci/taskcluster/mock.py | 36 +++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) create mode 100755 etc/ci/taskcluster/mock.py diff --git a/etc/ci/taskcluster/decisionlib.py b/etc/ci/taskcluster/decisionlib.py index 70bfb82cdea..c941f4915ab 100644 --- a/etc/ci/taskcluster/decisionlib.py +++ b/etc/ci/taskcluster/decisionlib.py @@ -194,7 +194,7 @@ class DecisionTask: task_id = taskcluster.slugId().decode("utf8") self.queue_service.createTask(task_id, payload) - print("Scheduled %s: %s" % (task_name, task_id)) + print("Scheduled %s" % task_name) return task_id diff --git a/etc/ci/taskcluster/mock.py b/etc/ci/taskcluster/mock.py new file mode 100755 index 00000000000..dc0ba65b192 --- /dev/null +++ b/etc/ci/taskcluster/mock.py @@ -0,0 +1,36 @@ +#!/usr/bin/python3 + +# Copyright 2018 The Servo Project Developers. See the COPYRIGHT +# file at the top-level directory of this distribution. +# +# Licensed under the Apache License, Version 2.0 or the MIT license +# , at your +# option. This file may not be copied, modified, or distributed +# except according to those terms. + +""" +Run the decision task with fake Taskcluster APIs, to catch Python errors before pushing. +""" + +import os +import sys +from unittest.mock import MagicMock + + +class TaskclusterRestFailure(Exception): + status_code = 404 + + +class Index: + def __init__(self, options): + pass + + def findTask(self, _): + raise TaskclusterRestFailure + + +Queue = stringDate = fromNow = slugId = os.environ = MagicMock() +sys.modules["taskcluster"] = sys.modules[__name__] +sys.dont_write_bytecode = True +exec(open("decision-task.py").read())