blob: 29bede000d762d8c2b28f8a4b01f0e90525c19ab [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
Chris Masone517ef482012-07-23 15:36:36 -070020 self.dependencies = []
Chris Masone8d6e6412012-06-28 11:20:56 -070021
22
23class FakeJob(object):
24 """Faked out RPC-client-side Job object."""
Chris Masone517ef482012-07-23 15:36:36 -070025 def __init__(self, id=0, statuses=[], hostnames=[]):
Chris Masone8d6e6412012-06-28 11:20:56 -070026 self.id = id
Chris Masone517ef482012-07-23 15:36:36 -070027 self.hostnames = hostnames if hostnames else ['host%d' % id]
Chris Masone8d6e6412012-06-28 11:20:56 -070028 self.owner = 'tester'
29 self.name = 'Fake Job %d' % self.id
30 self.statuses = statuses
31
32
33class FakeHost(object):
34 """Faked out RPC-client-side Host object."""
Chris Masone275ec902012-07-10 15:28:34 -070035 def __init__(self, hostname='', status='Ready'):
36 self.hostname = hostname
Chris Masone8d6e6412012-06-28 11:20:56 -070037 self.status = status
38
Chris Masone275ec902012-07-10 15:28:34 -070039
Chris Masone8d6e6412012-06-28 11:20:56 -070040class FakeLabel(object):
41 """Faked out RPC-client-side Label object."""
42 def __init__(self, id=0):
43 self.id = id
44
45
46class FakeStatus(object):
47 """Fake replacement for server-side job status objects.
48
49 @var status: 'GOOD', 'FAIL', 'ERROR', etc.
50 @var test_name: name of the test this is status for
51 @var reason: reason for failure, if any
52 @var aborted: present and True if the job was aborted. Optional.
53 """
Chris Masone6ea0cad2012-07-02 09:43:36 -070054 def __init__(self, code, name, reason, aborted=None, hostname=None):
Chris Masone8d6e6412012-06-28 11:20:56 -070055 self.status = code
56 self.test_name = name
57 self.reason = reason
Chris Masone6ea0cad2012-07-02 09:43:36 -070058 self.hostname = hostname if hostname else 'hostless'
Chris Masone8d6e6412012-06-28 11:20:56 -070059 self.entry = {}
60 self.test_started_time = '2012-11-11 11:11:11'
61 self.test_finished_time = '2012-11-11 12:12:12'
62 if aborted:
63 self.entry['aborted'] = True
Chris Masone6ea0cad2012-07-02 09:43:36 -070064 if hostname:
65 self.entry['host'] = {'hostname': hostname}
66
Chris Masonee3dcadb2012-07-31 12:16:19 -070067
Chris Masone6ea0cad2012-07-02 09:43:36 -070068 def __repr__(self):
69 return '%s\t%s\t%s: %s' % (self.status, self.test_name, self.reason,
70 self.hostname)
Chris Masone8d6e6412012-06-28 11:20:56 -070071
Chris Masonee3dcadb2012-07-31 12:16:19 -070072
Chris Masone8d6e6412012-06-28 11:20:56 -070073 def equals_record(self, status):
74 """Compares this object to a recorded status."""
Chris Masone8d6e6412012-06-28 11:20:56 -070075 if 'aborted' in self.entry and self.entry['aborted']:
Chris Masonee3dcadb2012-07-31 12:16:19 -070076 return status._status == 'ABORT'
Chris Masone6ea0cad2012-07-02 09:43:36 -070077 return (self.status == status._status and
Chris Masonee71a5152012-07-31 12:16:19 -070078 status._test_name.endswith(self.test_name) and
Chris Masone6ea0cad2012-07-02 09:43:36 -070079 self.reason == status._reason)
Chris Masonef63576d2012-06-29 11:13:31 -070080
Chris Masonee3dcadb2012-07-31 12:16:19 -070081
Chris Masone6ea0cad2012-07-02 09:43:36 -070082 def equals_hostname_record(self, status):
83 """Compares this object to a recorded status.
Chris Masonef63576d2012-06-29 11:13:31 -070084
Chris Masone6ea0cad2012-07-02 09:43:36 -070085 Expects the test name field of |status| to contain |self.hostname|.
86 """
87 return (self.status == status._status and
88 self.hostname in status._test_name and
89 self.reason == status._reason)