blob: cd186458d80c2cf32645fda84b696d31f9abf055 [file] [log] [blame]
Aviv Keshet6f455262013-03-01 16:02:29 -08001#pylint: disable-msg=C0111
Chris Masone8d6e6412012-06-28 11:20:56 -07002# Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
3# Use of this source code is governed by a BSD-style license that can be
4# found in the LICENSE file.
5
6"""Fakes for dynamic_suite-related unit tests."""
7
8
9class FakeControlData(object):
10 """A fake parsed control file data structure."""
Aviv Keshetd7959f32013-05-17 15:58:43 -070011 def __init__(self, suite, data, time='LONG', expr=False,
12 dependencies=None):
Chris Masone8d6e6412012-06-28 11:20:56 -070013 self.string = 'text-' + data
14 self.name = 'name-' + data
Chris Masone8906ab12012-07-23 15:37:56 -070015 self.path = None # Will be set during 'parsing'.
Chris Masone8d6e6412012-06-28 11:20:56 -070016 self.data = data
17 self.suite = suite
18 self.test_type = 'Client'
19 self.experimental = expr
Aviv Keshetd7959f32013-05-17 15:58:43 -070020 if not dependencies:
21 dependencies=[]
22 self.dependencies = dependencies
Dan Shief5b53f2013-01-22 10:22:01 -080023 self.time = time
Aviv Keshet6f455262013-03-01 16:02:29 -080024 self.retries = 0
Chris Masone8d6e6412012-06-28 11:20:56 -070025
26
27class FakeJob(object):
28 """Faked out RPC-client-side Job object."""
Chris Masone517ef482012-07-23 15:36:36 -070029 def __init__(self, id=0, statuses=[], hostnames=[]):
Chris Masone8d6e6412012-06-28 11:20:56 -070030 self.id = id
Chris Masone517ef482012-07-23 15:36:36 -070031 self.hostnames = hostnames if hostnames else ['host%d' % id]
Chris Masone8d6e6412012-06-28 11:20:56 -070032 self.owner = 'tester'
33 self.name = 'Fake Job %d' % self.id
34 self.statuses = statuses
35
36
37class FakeHost(object):
38 """Faked out RPC-client-side Host object."""
Chris Masonee99bcf22012-08-17 15:09:49 -070039 def __init__(self, hostname='', status='Ready', locked=False, locked_by=''):
Chris Masone275ec902012-07-10 15:28:34 -070040 self.hostname = hostname
Chris Masone8d6e6412012-06-28 11:20:56 -070041 self.status = status
Chris Masonee99bcf22012-08-17 15:09:49 -070042 self.locked = locked
43 self.locked_by = locked_by
Chris Masone8d6e6412012-06-28 11:20:56 -070044
Chris Masone275ec902012-07-10 15:28:34 -070045
Chris Masone8906ab12012-07-23 15:37:56 -070046 def __str__(self):
47 return '%s: %s. %s%s' % (
48 self.hostname, self.status,
49 'Locked' if self.locked else 'Unlocked',
50 ' by %s' % self.locked_by if self.locked else '')
51
52
Chris Masone8d6e6412012-06-28 11:20:56 -070053class FakeLabel(object):
54 """Faked out RPC-client-side Label object."""
55 def __init__(self, id=0):
56 self.id = id
57
58
59class FakeStatus(object):
60 """Fake replacement for server-side job status objects.
61
62 @var status: 'GOOD', 'FAIL', 'ERROR', etc.
63 @var test_name: name of the test this is status for
64 @var reason: reason for failure, if any
65 @var aborted: present and True if the job was aborted. Optional.
66 """
Chris Masone6ea0cad2012-07-02 09:43:36 -070067 def __init__(self, code, name, reason, aborted=None, hostname=None):
Chris Masone8d6e6412012-06-28 11:20:56 -070068 self.status = code
69 self.test_name = name
70 self.reason = reason
Chris Masone6ea0cad2012-07-02 09:43:36 -070071 self.hostname = hostname if hostname else 'hostless'
Chris Masone8d6e6412012-06-28 11:20:56 -070072 self.entry = {}
73 self.test_started_time = '2012-11-11 11:11:11'
74 self.test_finished_time = '2012-11-11 12:12:12'
75 if aborted:
76 self.entry['aborted'] = True
Chris Masone6ea0cad2012-07-02 09:43:36 -070077 if hostname:
78 self.entry['host'] = {'hostname': hostname}
79
Chris Masonee3dcadb2012-07-31 12:16:19 -070080
Chris Masone6ea0cad2012-07-02 09:43:36 -070081 def __repr__(self):
82 return '%s\t%s\t%s: %s' % (self.status, self.test_name, self.reason,
83 self.hostname)
Chris Masone8d6e6412012-06-28 11:20:56 -070084
Chris Masonee3dcadb2012-07-31 12:16:19 -070085
Chris Masone8d6e6412012-06-28 11:20:56 -070086 def equals_record(self, status):
87 """Compares this object to a recorded status."""
Chris Masone8d6e6412012-06-28 11:20:56 -070088 if 'aborted' in self.entry and self.entry['aborted']:
Chris Masonee3dcadb2012-07-31 12:16:19 -070089 return status._status == 'ABORT'
Chris Masone6ea0cad2012-07-02 09:43:36 -070090 return (self.status == status._status and
Chris Masonee71a5152012-07-31 12:16:19 -070091 status._test_name.endswith(self.test_name) and
Chris Masone6ea0cad2012-07-02 09:43:36 -070092 self.reason == status._reason)
Chris Masonef63576d2012-06-29 11:13:31 -070093
Chris Masonee3dcadb2012-07-31 12:16:19 -070094
Chris Masone6ea0cad2012-07-02 09:43:36 -070095 def equals_hostname_record(self, status):
96 """Compares this object to a recorded status.
Chris Masonef63576d2012-06-29 11:13:31 -070097
Chris Masone6ea0cad2012-07-02 09:43:36 -070098 Expects the test name field of |status| to contain |self.hostname|.
99 """
100 return (self.status == status._status and
101 self.hostname in status._test_name and
102 self.reason == status._reason)
Alex Miller176a29f2012-07-30 14:03:55 -0700103
104
105 def record_all(self, record):
106 pass
107
108
109 def is_good(self):
110 pass
111
112 def name(self):
113 return self.test_name