blob: aeeee62ee585b09b66e78696b8b642a2c9ce0188 [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 """
Chris Masone6ea0cad2012-07-02 09:43:36 -070051 def __init__(self, code, name, reason, aborted=None, hostname=None):
Chris Masone8d6e6412012-06-28 11:20:56 -070052 self.status = code
53 self.test_name = name
54 self.reason = reason
Chris Masone6ea0cad2012-07-02 09:43:36 -070055 self.hostname = hostname if hostname else 'hostless'
Chris Masone8d6e6412012-06-28 11:20:56 -070056 self.entry = {}
57 self.test_started_time = '2012-11-11 11:11:11'
58 self.test_finished_time = '2012-11-11 12:12:12'
59 if aborted:
60 self.entry['aborted'] = True
Chris Masone6ea0cad2012-07-02 09:43:36 -070061 if hostname:
62 self.entry['host'] = {'hostname': hostname}
63
64 def __repr__(self):
65 return '%s\t%s\t%s: %s' % (self.status, self.test_name, self.reason,
66 self.hostname)
Chris Masone8d6e6412012-06-28 11:20:56 -070067
68 def equals_record(self, status):
69 """Compares this object to a recorded status."""
Chris Masone8d6e6412012-06-28 11:20:56 -070070 if 'aborted' in self.entry and self.entry['aborted']:
71 return status == 'ABORT'
Chris Masone6ea0cad2012-07-02 09:43:36 -070072 return (self.status == status._status and
73 self.test_name == status._test_name and
74 self.reason == status._reason)
Chris Masonef63576d2012-06-29 11:13:31 -070075
Chris Masone6ea0cad2012-07-02 09:43:36 -070076 def equals_hostname_record(self, status):
77 """Compares this object to a recorded status.
Chris Masonef63576d2012-06-29 11:13:31 -070078
Chris Masone6ea0cad2012-07-02 09:43:36 -070079 Expects the test name field of |status| to contain |self.hostname|.
80 """
81 return (self.status == status._status and
82 self.hostname in status._test_name and
83 self.reason == status._reason)