Add decision task mocking

This commit is contained in:
Simon Sapin 2018-09-21 15:10:42 +02:00
parent d0a57e2303
commit ffd94e2849
2 changed files with 37 additions and 1 deletions

View file

@ -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

36
etc/ci/taskcluster/mock.py Executable file
View file

@ -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 <LICENSE-APACHE or
# http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
# <LICENSE-MIT or http://opensource.org/licenses/MIT>, 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())