blob: 7fded706dcb25cba1ac4c5de99446dc4bcf5814f [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
7
8class FakeControlData(object):
9 """A fake parsed control file data structure."""
Dan Shief5b53f2013-01-22 10:22:01 -080010 def __init__(self, suite, data, time='LONG', expr=False):
Chris Masone8d6e6412012-06-28 11:20:56 -070011 self.string = 'text-' + data
12 self.name = 'name-' + data
Chris Masone8906ab12012-07-23 15:37:56 -070013 self.path = None # Will be set during 'parsing'.
Chris Masone8d6e6412012-06-28 11:20:56 -070014 self.data = data
15 self.suite = suite
16 self.test_type = 'Client'
17 self.experimental = expr
Chris Masone517ef482012-07-23 15:36:36 -070018 self.dependencies = []
Dan Shief5b53f2013-01-22 10:22:01 -080019 self.time = time
Chris Masone8d6e6412012-06-28 11:20:56 -070020
21
22class FakeJob(object):
23 """Faked out RPC-client-side Job object."""
Chris Masone517ef482012-07-23 15:36:36 -070024 def __init__(self, id=0, statuses=[], hostnames=[]):
Chris Masone8d6e6412012-06-28 11:20:56 -070025 self.id = id
Chris Masone517ef482012-07-23 15:36:36 -070026 self.hostnames = hostnames if hostnames else ['host%d' % id]
Chris Masone8d6e6412012-06-28 11:20:56 -070027 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 Masonee99bcf22012-08-17 15:09:49 -070034 def __init__(self, hostname='', status='Ready', locked=False, locked_by=''):
Chris Masone275ec902012-07-10 15:28:34 -070035 self.hostname = hostname
Chris Masone8d6e6412012-06-28 11:20:56 -070036 self.status = status
Chris Masonee99bcf22012-08-17 15:09:49 -070037 self.locked = locked
38 self.locked_by = locked_by
Chris Masone8d6e6412012-06-28 11:20:56 -070039
Chris Masone275ec902012-07-10 15:28:34 -070040
Chris Masone8906ab12012-07-23 15:37:56 -070041 def __str__(self):
42 return '%s: %s. %s%s' % (
43 self.hostname, self.status,
44 'Locked' if self.locked else 'Unlocked',
45 ' by %s' % self.locked_by if self.locked else '')
46
47
Chris Masone8d6e6412012-06-28 11:20:56 -070048class FakeLabel(object):
49 """Faked out RPC-client-side Label object."""
50 def __init__(self, id=0):
51 self.id = id
52
53
54class FakeStatus(object):
55 """Fake replacement for server-side job status objects.
56
57 @var status: 'GOOD', 'FAIL', 'ERROR', etc.
58 @var test_name: name of the test this is status for
59 @var reason: reason for failure, if any
60 @var aborted: present and True if the job was aborted. Optional.
61 """
Chris Masone6ea0cad2012-07-02 09:43:36 -070062 def __init__(self, code, name, reason, aborted=None, hostname=None):
Chris Masone8d6e6412012-06-28 11:20:56 -070063 self.status = code
64 self.test_name = name
65 self.reason = reason
Chris Masone6ea0cad2012-07-02 09:43:36 -070066 self.hostname = hostname if hostname else 'hostless'
Chris Masone8d6e6412012-06-28 11:20:56 -070067 self.entry = {}
68 self.test_started_time = '2012-11-11 11:11:11'
69 self.test_finished_time = '2012-11-11 12:12:12'
70 if aborted:
71 self.entry['aborted'] = True
Chris Masone6ea0cad2012-07-02 09:43:36 -070072 if hostname:
73 self.entry['host'] = {'hostname': hostname}
74
Chris Masonee3dcadb2012-07-31 12:16:19 -070075
Chris Masone6ea0cad2012-07-02 09:43:36 -070076 def __repr__(self):
77 return '%s\t%s\t%s: %s' % (self.status, self.test_name, self.reason,
78 self.hostname)
Chris Masone8d6e6412012-06-28 11:20:56 -070079
Chris Masonee3dcadb2012-07-31 12:16:19 -070080
Chris Masone8d6e6412012-06-28 11:20:56 -070081 def equals_record(self, status):
82 """Compares this object to a recorded status."""
Chris Masone8d6e6412012-06-28 11:20:56 -070083 if 'aborted' in self.entry and self.entry['aborted']:
Chris Masonee3dcadb2012-07-31 12:16:19 -070084 return status._status == 'ABORT'
Chris Masone6ea0cad2012-07-02 09:43:36 -070085 return (self.status == status._status and
Chris Masonee71a5152012-07-31 12:16:19 -070086 status._test_name.endswith(self.test_name) and
Chris Masone6ea0cad2012-07-02 09:43:36 -070087 self.reason == status._reason)
Chris Masonef63576d2012-06-29 11:13:31 -070088
Chris Masonee3dcadb2012-07-31 12:16:19 -070089
Chris Masone6ea0cad2012-07-02 09:43:36 -070090 def equals_hostname_record(self, status):
91 """Compares this object to a recorded status.
Chris Masonef63576d2012-06-29 11:13:31 -070092
Chris Masone6ea0cad2012-07-02 09:43:36 -070093 Expects the test name field of |status| to contain |self.hostname|.
94 """
95 return (self.status == status._status and
96 self.hostname in status._test_name and
97 self.reason == status._reason)
Alex Miller176a29f2012-07-30 14:03:55 -070098
99
100 def record_all(self, record):
101 pass
102
103
104 def is_good(self):
105 pass
106
107 def name(self):
108 return self.test_name