blob: 0d8f6577703ecc06d7fc58c4606e59628006276f [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."""
Shuqian Zhaoab468812015-04-08 14:40:38 -070011 def __init__(self, suite, attributes, data, time='LONG', expr=False,
Fang Denge3bc24b2014-03-17 15:19:46 -070012 dependencies=None, job_retries=0):
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
Shuqian Zhaoab468812015-04-08 14:40:38 -070018 self.attributes = attributes
Chris Masone8d6e6412012-06-28 11:20:56 -070019 self.test_type = 'Client'
20 self.experimental = expr
Aviv Keshetd7959f32013-05-17 15:58:43 -070021 if not dependencies:
22 dependencies=[]
23 self.dependencies = dependencies
Dan Shief5b53f2013-01-22 10:22:01 -080024 self.time = time
Aviv Keshet6f455262013-03-01 16:02:29 -080025 self.retries = 0
Dan Shi6eedadb2013-12-04 15:38:01 -080026 self.sync_count = 1
Fang Denge3bc24b2014-03-17 15:19:46 -070027 self.job_retries = job_retries
Dan Shic566a182014-05-06 12:42:55 -070028 self.bug_template = {}
Dan Shiec1d47d2015-02-13 11:38:13 -080029 self.require_ssp = None
Chris Masone8d6e6412012-06-28 11:20:56 -070030
31
32class FakeJob(object):
33 """Faked out RPC-client-side Job object."""
Aviv Keshet133beb12013-08-20 14:37:13 -070034 def __init__(self, id=0, statuses=[], hostnames=[], parent_job_id=None):
Chris Masone8d6e6412012-06-28 11:20:56 -070035 self.id = id
Chris Masone517ef482012-07-23 15:36:36 -070036 self.hostnames = hostnames if hostnames else ['host%d' % id]
Chris Masone8d6e6412012-06-28 11:20:56 -070037 self.owner = 'tester'
38 self.name = 'Fake Job %d' % self.id
39 self.statuses = statuses
Aviv Keshet133beb12013-08-20 14:37:13 -070040 self.parent_job_id = parent_job_id
Chris Masone8d6e6412012-06-28 11:20:56 -070041
42
43class FakeHost(object):
44 """Faked out RPC-client-side Host object."""
Chris Masonee99bcf22012-08-17 15:09:49 -070045 def __init__(self, hostname='', status='Ready', locked=False, locked_by=''):
Chris Masone275ec902012-07-10 15:28:34 -070046 self.hostname = hostname
Chris Masone8d6e6412012-06-28 11:20:56 -070047 self.status = status
Chris Masonee99bcf22012-08-17 15:09:49 -070048 self.locked = locked
49 self.locked_by = locked_by
Chris Masone8d6e6412012-06-28 11:20:56 -070050
Chris Masone275ec902012-07-10 15:28:34 -070051
Chris Masone8906ab12012-07-23 15:37:56 -070052 def __str__(self):
53 return '%s: %s. %s%s' % (
54 self.hostname, self.status,
55 'Locked' if self.locked else 'Unlocked',
56 ' by %s' % self.locked_by if self.locked else '')
57
58
Chris Masone8d6e6412012-06-28 11:20:56 -070059class FakeLabel(object):
60 """Faked out RPC-client-side Label object."""
61 def __init__(self, id=0):
62 self.id = id
63
64
65class FakeStatus(object):
66 """Fake replacement for server-side job status objects.
67
68 @var status: 'GOOD', 'FAIL', 'ERROR', etc.
69 @var test_name: name of the test this is status for
70 @var reason: reason for failure, if any
71 @var aborted: present and True if the job was aborted. Optional.
72 """
Fang Deng5c508332014-03-19 10:26:00 -070073 def __init__(self, code, name, reason, aborted=None,
74 hostname=None, subdir='fake_Test.tag.subdir_tag',
75 job_tag='id-owner/hostname'):
Chris Masone8d6e6412012-06-28 11:20:56 -070076 self.status = code
77 self.test_name = name
78 self.reason = reason
Chris Masone6ea0cad2012-07-02 09:43:36 -070079 self.hostname = hostname if hostname else 'hostless'
Chris Masone8d6e6412012-06-28 11:20:56 -070080 self.entry = {}
81 self.test_started_time = '2012-11-11 11:11:11'
82 self.test_finished_time = '2012-11-11 12:12:12'
Fang Deng5c508332014-03-19 10:26:00 -070083 self.job_tag=job_tag
84 self.subdir=subdir
Chris Masone8d6e6412012-06-28 11:20:56 -070085 if aborted:
86 self.entry['aborted'] = True
Chris Masone6ea0cad2012-07-02 09:43:36 -070087 if hostname:
88 self.entry['host'] = {'hostname': hostname}
89
Chris Masonee3dcadb2012-07-31 12:16:19 -070090
Chris Masone6ea0cad2012-07-02 09:43:36 -070091 def __repr__(self):
92 return '%s\t%s\t%s: %s' % (self.status, self.test_name, self.reason,
93 self.hostname)
Chris Masone8d6e6412012-06-28 11:20:56 -070094
Chris Masonee3dcadb2012-07-31 12:16:19 -070095
Chris Masone8d6e6412012-06-28 11:20:56 -070096 def equals_record(self, status):
97 """Compares this object to a recorded status."""
Chris Masone8d6e6412012-06-28 11:20:56 -070098 if 'aborted' in self.entry and self.entry['aborted']:
Chris Masonee3dcadb2012-07-31 12:16:19 -070099 return status._status == 'ABORT'
Chris Masone6ea0cad2012-07-02 09:43:36 -0700100 return (self.status == status._status and
Chris Masonee71a5152012-07-31 12:16:19 -0700101 status._test_name.endswith(self.test_name) and
Chris Masone6ea0cad2012-07-02 09:43:36 -0700102 self.reason == status._reason)
Chris Masonef63576d2012-06-29 11:13:31 -0700103
Chris Masonee3dcadb2012-07-31 12:16:19 -0700104
Chris Masone6ea0cad2012-07-02 09:43:36 -0700105 def equals_hostname_record(self, status):
106 """Compares this object to a recorded status.
Chris Masonef63576d2012-06-29 11:13:31 -0700107
Chris Masone6ea0cad2012-07-02 09:43:36 -0700108 Expects the test name field of |status| to contain |self.hostname|.
109 """
110 return (self.status == status._status and
111 self.hostname in status._test_name and
112 self.reason == status._reason)
Alex Miller176a29f2012-07-30 14:03:55 -0700113
114
115 def record_all(self, record):
116 pass
117
118
119 def is_good(self):
120 pass
121
122 def name(self):
123 return self.test_name