blob: 892bc71fd9dc0788e46f9b0c8bc158acc7da8a45 [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,
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
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
Fang Denge3bc24b2014-03-17 15:19:46 -070026 self.job_retries = job_retries
Chris Masone8d6e6412012-06-28 11:20:56 -070027
28
29class FakeJob(object):
30 """Faked out RPC-client-side Job object."""
Aviv Keshet133beb12013-08-20 14:37:13 -070031 def __init__(self, id=0, statuses=[], hostnames=[], parent_job_id=None):
Chris Masone8d6e6412012-06-28 11:20:56 -070032 self.id = id
Chris Masone517ef482012-07-23 15:36:36 -070033 self.hostnames = hostnames if hostnames else ['host%d' % id]
Chris Masone8d6e6412012-06-28 11:20:56 -070034 self.owner = 'tester'
35 self.name = 'Fake Job %d' % self.id
36 self.statuses = statuses
Aviv Keshet133beb12013-08-20 14:37:13 -070037 self.parent_job_id = parent_job_id
Chris Masone8d6e6412012-06-28 11:20:56 -070038
39
40class FakeHost(object):
41 """Faked out RPC-client-side Host object."""
Chris Masonee99bcf22012-08-17 15:09:49 -070042 def __init__(self, hostname='', status='Ready', locked=False, locked_by=''):
Chris Masone275ec902012-07-10 15:28:34 -070043 self.hostname = hostname
Chris Masone8d6e6412012-06-28 11:20:56 -070044 self.status = status
Chris Masonee99bcf22012-08-17 15:09:49 -070045 self.locked = locked
46 self.locked_by = locked_by
Chris Masone8d6e6412012-06-28 11:20:56 -070047
Chris Masone275ec902012-07-10 15:28:34 -070048
Chris Masone8906ab12012-07-23 15:37:56 -070049 def __str__(self):
50 return '%s: %s. %s%s' % (
51 self.hostname, self.status,
52 'Locked' if self.locked else 'Unlocked',
53 ' by %s' % self.locked_by if self.locked else '')
54
55
Chris Masone8d6e6412012-06-28 11:20:56 -070056class FakeLabel(object):
57 """Faked out RPC-client-side Label object."""
58 def __init__(self, id=0):
59 self.id = id
60
61
62class FakeStatus(object):
63 """Fake replacement for server-side job status objects.
64
65 @var status: 'GOOD', 'FAIL', 'ERROR', etc.
66 @var test_name: name of the test this is status for
67 @var reason: reason for failure, if any
68 @var aborted: present and True if the job was aborted. Optional.
69 """
Fang Deng5c508332014-03-19 10:26:00 -070070 def __init__(self, code, name, reason, aborted=None,
71 hostname=None, subdir='fake_Test.tag.subdir_tag',
72 job_tag='id-owner/hostname'):
Chris Masone8d6e6412012-06-28 11:20:56 -070073 self.status = code
74 self.test_name = name
75 self.reason = reason
Chris Masone6ea0cad2012-07-02 09:43:36 -070076 self.hostname = hostname if hostname else 'hostless'
Chris Masone8d6e6412012-06-28 11:20:56 -070077 self.entry = {}
78 self.test_started_time = '2012-11-11 11:11:11'
79 self.test_finished_time = '2012-11-11 12:12:12'
Fang Deng5c508332014-03-19 10:26:00 -070080 self.job_tag=job_tag
81 self.subdir=subdir
Chris Masone8d6e6412012-06-28 11:20:56 -070082 if aborted:
83 self.entry['aborted'] = True
Chris Masone6ea0cad2012-07-02 09:43:36 -070084 if hostname:
85 self.entry['host'] = {'hostname': hostname}
86
Chris Masonee3dcadb2012-07-31 12:16:19 -070087
Chris Masone6ea0cad2012-07-02 09:43:36 -070088 def __repr__(self):
89 return '%s\t%s\t%s: %s' % (self.status, self.test_name, self.reason,
90 self.hostname)
Chris Masone8d6e6412012-06-28 11:20:56 -070091
Chris Masonee3dcadb2012-07-31 12:16:19 -070092
Chris Masone8d6e6412012-06-28 11:20:56 -070093 def equals_record(self, status):
94 """Compares this object to a recorded status."""
Chris Masone8d6e6412012-06-28 11:20:56 -070095 if 'aborted' in self.entry and self.entry['aborted']:
Chris Masonee3dcadb2012-07-31 12:16:19 -070096 return status._status == 'ABORT'
Chris Masone6ea0cad2012-07-02 09:43:36 -070097 return (self.status == status._status and
Chris Masonee71a5152012-07-31 12:16:19 -070098 status._test_name.endswith(self.test_name) and
Chris Masone6ea0cad2012-07-02 09:43:36 -070099 self.reason == status._reason)
Chris Masonef63576d2012-06-29 11:13:31 -0700100
Chris Masonee3dcadb2012-07-31 12:16:19 -0700101
Chris Masone6ea0cad2012-07-02 09:43:36 -0700102 def equals_hostname_record(self, status):
103 """Compares this object to a recorded status.
Chris Masonef63576d2012-06-29 11:13:31 -0700104
Chris Masone6ea0cad2012-07-02 09:43:36 -0700105 Expects the test name field of |status| to contain |self.hostname|.
106 """
107 return (self.status == status._status and
108 self.hostname in status._test_name and
109 self.reason == status._reason)
Alex Miller176a29f2012-07-30 14:03:55 -0700110
111
112 def record_all(self, record):
113 pass
114
115
116 def is_good(self):
117 pass
118
119 def name(self):
120 return self.test_name