~canonical-launchpad-branches/launchpad-buildd/trunk

« back to all changes in this revision

Viewing changes to lpbuildd/tests/matchers.py

  • Committer: Colin Watson
  • Date: 2017-05-11 08:34:07 UTC
  • mfrom: (215.1.1 extended-snap-status)
  • Revision ID: cjwatson@canonical.com-20170511083407-2jvw6phrd50strdk
[r=wgrant] Record the branch revision used to build a snap and return it along with other XML-RPC status information (LP: #1679157).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright 2017 Canonical Ltd.  This software is licensed under the
2
 
# GNU Affero General Public License version 3 (see the file LICENSE).
3
 
 
4
 
__metaclass__ = type
5
 
 
6
 
from testtools.matchers import (
7
 
    Equals,
8
 
    Matcher,
9
 
    MatchesDict,
10
 
    )
11
 
 
12
 
 
13
 
class HasWaitingFiles(Matcher):
14
 
    """Match files that have been added using `builder.addWaitingFile`."""
15
 
 
16
 
    def __init__(self, files):
17
 
        self.files = files
18
 
 
19
 
    @classmethod
20
 
    def byEquality(cls, files):
21
 
        return cls(
22
 
            {name: Equals(contents) for name, contents in files.items()})
23
 
 
24
 
    def match(self, builder):
25
 
        waiting_file_contents = {}
26
 
        for name in builder.waitingfiles:
27
 
            cache_path = builder.cachePath(builder.waitingfiles[name])
28
 
            with open(cache_path, "rb") as f:
29
 
                waiting_file_contents[name] = f.read()
30
 
        return MatchesDict(self.files).match(waiting_file_contents)