1# Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
2# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
5"""Comparators for use in dynamic_suite module unit tests."""
6
7import mox
8
9class StatusContains(mox.Comparator):
10    @staticmethod
11    def CreateFromStrings(status=None, test_name=None, reason=None):
12        status_comp = mox.StrContains(status) if status else mox.IgnoreArg()
13        name_comp = mox.StrContains(test_name) if test_name else mox.IgnoreArg()
14        reason_comp = mox.StrContains(reason) if reason else mox.IgnoreArg()
15        return StatusContains(status_comp, name_comp, reason_comp)
16
17
18    def __init__(self, status=mox.IgnoreArg(), test_name=mox.IgnoreArg(),
19                 reason=mox.IgnoreArg()):
20        """Initialize.
21
22        Takes mox.Comparator objects to apply to job_status.Status
23        member variables.
24
25        @param status: status code, e.g. 'INFO', 'START', etc.
26        @param test_name: expected test name.
27        @param reason: expected reason
28        """
29        self._status = status
30        self._test_name = test_name
31        self._reason = reason
32
33
34    def equals(self, rhs):
35        """Check to see if fields match base_job.status_log_entry obj in rhs.
36
37        @param rhs: base_job.status_log_entry object to match.
38        @return boolean
39        """
40        return (self._status.equals(rhs.status_code) and
41                self._test_name.equals(rhs.operation) and
42                self._reason.equals(rhs.message))
43
44
45    def __repr__(self):
46        return '<Status containing \'%s\t%s\t%s\'>' % (self._status,
47                                                       self._test_name,
48                                                       self._reason)
49