blob: 9bcf86c32fcf6d5277ce6fd53d61b1633c4eddd7 [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."""
Chris Masone275ec902012-07-10 15:28:34 -070034 def __init__(self, hostname='', status='Ready'):
35 self.hostname = hostname
Chris Masone8d6e6412012-06-28 11:20:56 -070036 self.status = status
37
Chris Masone275ec902012-07-10 15:28:34 -070038
Chris Masone8d6e6412012-06-28 11:20:56 -070039class FakeLabel(object):
40 """Faked out RPC-client-side Label object."""
41 def __init__(self, id=0):
42 self.id = id
43
44
45class FakeStatus(object):
46 """Fake replacement for server-side job status objects.
47
48 @var status: 'GOOD', 'FAIL', 'ERROR', etc.
49 @var test_name: name of the test this is status for
50 @var reason: reason for failure, if any
51 @var aborted: present and True if the job was aborted. Optional.
52 """
Chris Masone6ea0cad2012-07-02 09:43:36 -070053 def __init__(self, code, name, reason, aborted=None, hostname=None):
Chris Masone8d6e6412012-06-28 11:20:56 -070054 self.status = code
55 self.test_name = name
56 self.reason = reason
Chris Masone6ea0cad2012-07-02 09:43:36 -070057 self.hostname = hostname if hostname else 'hostless'
Chris Masone8d6e6412012-06-28 11:20:56 -070058 self.entry = {}
59 self.test_started_time = '2012-11-11 11:11:11'
60 self.test_finished_time = '2012-11-11 12:12:12'
61 if aborted:
62 self.entry['aborted'] = True
Chris Masone6ea0cad2012-07-02 09:43:36 -070063 if hostname:
64 self.entry['host'] = {'hostname': hostname}
65
66 def __repr__(self):
67 return '%s\t%s\t%s: %s' % (self.status, self.test_name, self.reason,
68 self.hostname)
Chris Masone8d6e6412012-06-28 11:20:56 -070069
70 def equals_record(self, status):
71 """Compares this object to a recorded status."""
Chris Masone8d6e6412012-06-28 11:20:56 -070072 if 'aborted' in self.entry and self.entry['aborted']:
73 return status == 'ABORT'
Chris Masone6ea0cad2012-07-02 09:43:36 -070074 return (self.status == status._status and
75 self.test_name == status._test_name and
76 self.reason == status._reason)
Chris Masonef63576d2012-06-29 11:13:31 -070077
Chris Masone6ea0cad2012-07-02 09:43:36 -070078 def equals_hostname_record(self, status):
79 """Compares this object to a recorded status.
Chris Masonef63576d2012-06-29 11:13:31 -070080
Chris Masone6ea0cad2012-07-02 09:43:36 -070081 Expects the test name field of |status| to contain |self.hostname|.
82 """
83 return (self.status == status._status and
84 self.hostname in status._test_name and
85 self.reason == status._reason)