Skip to content

Commit

Permalink
Code coverage for decisionlib
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonSapin committed Oct 9, 2018
1 parent 62e4f70 commit 09d8339
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 15 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -19,6 +19,7 @@
*.csv
*.rej
*.orig
.coverage
.DS_Store
Servo.app
.config.mk.last
Expand Down
Empty file modified etc/memory_reports_over_time.py 100644 → 100755
Empty file.
9 changes: 5 additions & 4 deletions etc/taskcluster/decision_task.py
Expand Up @@ -17,14 +17,15 @@ def main(task_for, mock=False):
if mock:
windows_release()
linux_wpt()
linux_build_task("Indexed by task definition").find_or_create()

# https://tools.taskcluster.net/hooks/project-servo/daily
elif task_for == "daily":
daily_tasks_setup()
with_rust_nightly()
android_arm32()

else:
else: # pragma: no cover
raise ValueError("Unrecognized $TASK_FOR value: %r", task_for)


Expand Down Expand Up @@ -64,8 +65,8 @@ def linux_tidy_unit():
./mach test-unit
./mach package --dev
./mach test-tidy --no-progress --self-test
python2.7 ./etc/memory_reports_over_time.py --test
python3 ./etc/taskcluster/mock.py
./etc/memory_reports_over_time.py --test
./etc/taskcluster/mock.py
./etc/ci/lockfile_changed.sh
./etc/ci/check_no_panic.sh
""").create()
Expand Down Expand Up @@ -294,5 +295,5 @@ def windows_build_task(name):
CONFIG.repacked_msi_files_expire_in = build_dependencies_artifacts_expire_in


if __name__ == "__main__":
if __name__ == "__main__": # pragma: no cover
main(task_for=os.environ["TASK_FOR"])
13 changes: 5 additions & 8 deletions etc/taskcluster/decisionlib.py
Expand Up @@ -82,8 +82,6 @@ def from_now_json(self, offset):

CONFIG = Config()
SHARED = Shared()
from_now_json = SHARED.from_now_json
now = SHARED.now


def chaining(op, attr):
Expand Down Expand Up @@ -127,7 +125,7 @@ def __init__(self, name):

with_extra = chaining(update_attr, "extra")

def build_worker_payload(self):
def build_worker_payload(self): # pragma: no cover
raise NotImplementedError

def create(self):
Expand Down Expand Up @@ -184,10 +182,9 @@ def find_or_create(self, index_path=None):
return task_id

try:
result = SHARED.index_service.findTask(index_path)
task_id = result["taskId"]
task_id = SHARED.index_service.findTask(index_path)["taskId"]
except taskcluster.TaskclusterRestFailure as e:
if e.status_code != 404:
if e.status_code != 404: # pragma: no cover
raise
self.routes.append("index." + index_path)
task_id = self.create()
Expand All @@ -208,7 +205,7 @@ def __init__(self, *args, **kwargs):
with_mounts = chaining(append_to_attr, "mounts")
with_env = chaining(update_attr, "env")

def build_command(self):
def build_command(self): # pragma: no cover
raise NotImplementedError

def build_worker_payload(self):
Expand Down Expand Up @@ -263,7 +260,7 @@ def with_directory_mount(self, url_or_artifact_name, task_id=None, sha256=None,
raise ValueError(
"%r does not appear to be in one of the supported formats: %r"
% (url_or_artifact_name, ", ".join(supported_formats))
)
) # pragma: no cover


class WindowsGenericWorkerTask(GenericWorkerTask):
Expand Down
2 changes: 1 addition & 1 deletion etc/taskcluster/docker/base.dockerfile
Expand Up @@ -15,7 +15,7 @@ RUN \
ca-certificates \
#
# Running mach
python2.7 \
python \
virtualenv \
#
# Installing rustup and sccache (build dockerfile) or fetching build artifacts (run tasks)
Expand Down
3 changes: 3 additions & 0 deletions etc/taskcluster/docker/build.dockerfile
Expand Up @@ -2,6 +2,9 @@

RUN \
apt-get install -qy --no-install-recommends \
#
# Testing decisionlib (see etc/taskcluster/mock.py)
python3-coverage \
#
# Multiple C/C++ dependencies built from source
g++ \
Expand Down
12 changes: 10 additions & 2 deletions etc/taskcluster/mock.py
@@ -1,4 +1,4 @@
#!/usr/bin/python3
#!/bin/bash

# Copyright 2018 The Servo Project Developers. See the COPYRIGHT
# file at the top-level directory of this distribution.
Expand All @@ -9,6 +9,12 @@
# option. This file may not be copied, modified, or distributed
# except according to those terms.

''''set -e
python3 -m coverage run $0
python3 -m coverage report -m --fail-under 100
exit
'''
"""
Run the decision task with fake Taskcluster APIs, to catch Python errors before pushing.
"""
Expand All @@ -29,7 +35,9 @@ def findTask(self, _):
raise TaskclusterRestFailure
Queue = stringDate = fromNow = slugId = MagicMock()
stringDate = str
slugId = b"id".lower
Queue = fromNow = MagicMock()
sys.modules["taskcluster"] = sys.modules[__name__]
sys.dont_write_bytecode = True
os.environ.update(**{k: k for k in "TASK_ID TASK_OWNER TASK_SOURCE GIT_URL GIT_SHA".split()})
Expand Down

0 comments on commit 09d8339

Please sign in to comment.