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