blob: b704929669f4dd6c8e24130e86826b7adc6fea6d [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
Dan Shi6eedadb2013-12-04 15:38:01 -080025 self.sync_count = 1
Chris Masone8d6e6412012-06-28 11:20:56 -070026
27
28class FakeJob(object):
29 """Faked out RPC-client-side Job object."""
Aviv Keshet133beb12013-08-20 14:37:13 -070030 def __init__(self, id=0, statuses=[], hostnames=[], parent_job_id=None):
Chris Masone8d6e6412012-06-28 11:20:56 -070031 self.id = id
Chris Masone517ef482012-07-23 15:36:36 -070032 self.hostnames = hostnames if hostnames else ['host%d' % id]
Chris Masone8d6e6412012-06-28 11:20:56 -070033 self.owner = 'tester'
34 self.name = 'Fake Job %d' % self.id
35 self.statuses = statuses
Aviv Keshet133beb12013-08-20 14:37:13 -070036 self.parent_job_id = parent_job_id
Chris Masone8d6e6412012-06-28 11:20:56 -070037
38
39class FakeHost(object):
40 """Faked out RPC-client-side Host object."""
Chris Masonee99bcf22012-08-17 15:09:49 -070041 def __init__(self, hostname='', status='Ready', locked=False, locked_by=''):
Chris Masone275ec902012-07-10 15:28:34 -070042 self.hostname = hostname
Chris Masone8d6e6412012-06-28 11:20:56 -070043 self.status = status
Chris Masonee99bcf22012-08-17 15:09:49 -070044 self.locked = locked
45 self.locked_by = locked_by
Chris Masone8d6e6412012-06-28 11:20:56 -070046
Chris Masone275ec902012-07-10 15:28:34 -070047
Chris Masone8906ab12012-07-23 15:37:56 -070048 def __str__(self):
49 return '%s: %s. %s%s' % (
50 self.hostname, self.status,
51 'Locked' if self.locked else 'Unlocked',
52 ' by %s' % self.locked_by if self.locked else '')
53
54
Chris Masone8d6e6412012-06-28 11:20:56 -070055class FakeLabel(object):
56 """Faked out RPC-client-side Label object."""
57 def __init__(self, id=0):
58 self.id = id
59
60
61class FakeStatus(object):
62 """Fake replacement for server-side job status objects.
63
64 @var status: 'GOOD', 'FAIL', 'ERROR', etc.
65 @var test_name: name of the test this is status for
66 @var reason: reason for failure, if any
67 @var aborted: present and True if the job was aborted. Optional.
68 """
Fang Deng5c508332014-03-19 10:26:00 -070069 def __init__(self, code, name, reason, aborted=None,
70 hostname=None, subdir='fake_Test.tag.subdir_tag',
71 job_tag='id-owner/hostname'):
Chris Masone8d6e6412012-06-28 11:20:56 -070072 self.status = code
73 self.test_name = name
74 self.reason = reason
Chris Masone6ea0cad2012-07-02 09:43:36 -070075 self.hostname = hostname if hostname else 'hostless'
Chris Masone8d6e6412012-06-28 11:20:56 -070076 self.entry = {}
77 self.test_started_time = '2012-11-11 11:11:11'
78 self.test_finished_time = '2012-11-11 12:12:12'
Fang Deng5c508332014-03-19 10:26:00 -070079 self.job_tag=job_tag
80 self.subdir=subdir
Chris Masone8d6e6412012-06-28 11:20:56 -070081 if aborted:
82 self.entry['aborted'] = True
Chris Masone6ea0cad2012-07-02 09:43:36 -070083 if hostname:
84 self.entry['host'] = {'hostname': hostname}
85
Chris Masonee3dcadb2012-07-31 12:16:19 -070086
Chris Masone6ea0cad2012-07-02 09:43:36 -070087 def __repr__(self):
88 return '%s\t%s\t%s: %s' % (self.status, self.test_name, self.reason,
89 self.hostname)
Chris Masone8d6e6412012-06-28 11:20:56 -070090
Chris Masonee3dcadb2012-07-31 12:16:19 -070091
Chris Masone8d6e6412012-06-28 11:20:56 -070092 def equals_record(self, status):
93 """Compares this object to a recorded status."""
Chris Masone8d6e6412012-06-28 11:20:56 -070094 if 'aborted' in self.entry and self.entry['aborted']:
Chris Masonee3dcadb2012-07-31 12:16:19 -070095 return status._status == 'ABORT'
Chris Masone6ea0cad2012-07-02 09:43:36 -070096 return (self.status == status._status and
Chris Masonee71a5152012-07-31 12:16:19 -070097 status._test_name.endswith(self.test_name) and
Chris Masone6ea0cad2012-07-02 09:43:36 -070098 self.reason == status._reason)
Chris Masonef63576d2012-06-29 11:13:31 -070099
Chris Masonee3dcadb2012-07-31 12:16:19 -0700100
Chris Masone6ea0cad2012-07-02 09:43:36 -0700101 def equals_hostname_record(self, status):
102 """Compares this object to a recorded status.
Chris Masonef63576d2012-06-29 11:13:31 -0700103
Chris Masone6ea0cad2012-07-02 09:43:36 -0700104 Expects the test name field of |status| to contain |self.hostname|.
105 """
106 return (self.status == status._status and
107 self.hostname in status._test_name and
108 self.reason == status._reason)
Alex Miller176a29f2012-07-30 14:03:55 -0700109
110
111 def record_all(self, record):
112 pass
113
114
115 def is_good(self):
116 pass
117
118 def name(self):
119 return self.test_name