blob: abcea41508c15f5532ed1304a5dfd51c4ab058ce [file] [log] [blame]
Chris Masone8d6e6412012-06-28 11:20:56 -07001# 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"""Fakes for dynamic_suite-related unit tests."""
6
7
8class FakeControlData(object):
9 """A fake parsed control file data structure."""
10 def __init__(self, suite, data, expr=False):
11 self.string = 'text-' + data
12 self.name = 'name-' + data
13 self.data = data
14 self.suite = suite
15 self.test_type = 'Client'
16 self.experimental = expr
17
18
19class FakeJob(object):
20 """Faked out RPC-client-side Job object."""
21 def __init__(self, id=0, statuses=[]):
22 self.id = id
23 self.hostname = 'host%d' % id
24 self.owner = 'tester'
25 self.name = 'Fake Job %d' % self.id
26 self.statuses = statuses
27
28
29class FakeHost(object):
30 """Faked out RPC-client-side Host object."""
31 def __init__(self, status='Ready'):
32 self.status = status
33
34class FakeLabel(object):
35 """Faked out RPC-client-side Label object."""
36 def __init__(self, id=0):
37 self.id = id
38
39
40class FakeStatus(object):
41 """Fake replacement for server-side job status objects.
42
43 @var status: 'GOOD', 'FAIL', 'ERROR', etc.
44 @var test_name: name of the test this is status for
45 @var reason: reason for failure, if any
46 @var aborted: present and True if the job was aborted. Optional.
47 """
48 def __init__(self, code, name, reason, aborted=None):
49 self.status = code
50 self.test_name = name
51 self.reason = reason
52 self.entry = {}
53 self.test_started_time = '2012-11-11 11:11:11'
54 self.test_finished_time = '2012-11-11 12:12:12'
55 if aborted:
56 self.entry['aborted'] = True
57
58 def equals_record(self, status):
59 """Compares this object to a recorded status."""
60 return self._equals_record(status._status, status._test_name,
61 status._reason)
62
63 def _equals_record(self, status, name, reason=None):
64 """Compares this object and fields of recorded status."""
65 if 'aborted' in self.entry and self.entry['aborted']:
66 return status == 'ABORT'
67 return (self.status == status and
68 self.test_name == name and
69 self.reason == reason)