Chris Masone | 8d6e641 | 2012-06-28 11:20:56 -0700 | [diff] [blame] | 1 | # 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 | |
Chris Masone | f63576d | 2012-06-29 11:13:31 -0700 | [diff] [blame] | 7 | import datetime |
| 8 | from autotest_lib.server.cros import job_status |
| 9 | |
Chris Masone | 8d6e641 | 2012-06-28 11:20:56 -0700 | [diff] [blame] | 10 | |
| 11 | class FakeControlData(object): |
| 12 | """A fake parsed control file data structure.""" |
| 13 | def __init__(self, suite, data, expr=False): |
| 14 | self.string = 'text-' + data |
| 15 | self.name = 'name-' + data |
| 16 | self.data = data |
| 17 | self.suite = suite |
| 18 | self.test_type = 'Client' |
| 19 | self.experimental = expr |
| 20 | |
| 21 | |
| 22 | class FakeJob(object): |
| 23 | """Faked out RPC-client-side Job object.""" |
| 24 | def __init__(self, id=0, statuses=[]): |
| 25 | self.id = id |
| 26 | self.hostname = 'host%d' % id |
| 27 | self.owner = 'tester' |
| 28 | self.name = 'Fake Job %d' % self.id |
| 29 | self.statuses = statuses |
| 30 | |
| 31 | |
| 32 | class FakeHost(object): |
| 33 | """Faked out RPC-client-side Host object.""" |
| 34 | def __init__(self, status='Ready'): |
| 35 | self.status = status |
| 36 | |
| 37 | class FakeLabel(object): |
| 38 | """Faked out RPC-client-side Label object.""" |
| 39 | def __init__(self, id=0): |
| 40 | self.id = id |
| 41 | |
| 42 | |
| 43 | class FakeStatus(object): |
| 44 | """Fake replacement for server-side job status objects. |
| 45 | |
| 46 | @var status: 'GOOD', 'FAIL', 'ERROR', etc. |
| 47 | @var test_name: name of the test this is status for |
| 48 | @var reason: reason for failure, if any |
| 49 | @var aborted: present and True if the job was aborted. Optional. |
| 50 | """ |
Chris Masone | 6ea0cad | 2012-07-02 09:43:36 -0700 | [diff] [blame^] | 51 | def __init__(self, code, name, reason, aborted=None, hostname=None): |
Chris Masone | 8d6e641 | 2012-06-28 11:20:56 -0700 | [diff] [blame] | 52 | self.status = code |
| 53 | self.test_name = name |
| 54 | self.reason = reason |
Chris Masone | 6ea0cad | 2012-07-02 09:43:36 -0700 | [diff] [blame^] | 55 | self.hostname = hostname if hostname else 'hostless' |
Chris Masone | 8d6e641 | 2012-06-28 11:20:56 -0700 | [diff] [blame] | 56 | self.entry = {} |
| 57 | self.test_started_time = '2012-11-11 11:11:11' |
| 58 | self.test_finished_time = '2012-11-11 12:12:12' |
| 59 | if aborted: |
| 60 | self.entry['aborted'] = True |
Chris Masone | 6ea0cad | 2012-07-02 09:43:36 -0700 | [diff] [blame^] | 61 | if hostname: |
| 62 | self.entry['host'] = {'hostname': hostname} |
| 63 | |
| 64 | def __repr__(self): |
| 65 | return '%s\t%s\t%s: %s' % (self.status, self.test_name, self.reason, |
| 66 | self.hostname) |
Chris Masone | 8d6e641 | 2012-06-28 11:20:56 -0700 | [diff] [blame] | 67 | |
| 68 | def equals_record(self, status): |
| 69 | """Compares this object to a recorded status.""" |
Chris Masone | 8d6e641 | 2012-06-28 11:20:56 -0700 | [diff] [blame] | 70 | if 'aborted' in self.entry and self.entry['aborted']: |
| 71 | return status == 'ABORT' |
Chris Masone | 6ea0cad | 2012-07-02 09:43:36 -0700 | [diff] [blame^] | 72 | return (self.status == status._status and |
| 73 | self.test_name == status._test_name and |
| 74 | self.reason == status._reason) |
Chris Masone | f63576d | 2012-06-29 11:13:31 -0700 | [diff] [blame] | 75 | |
Chris Masone | 6ea0cad | 2012-07-02 09:43:36 -0700 | [diff] [blame^] | 76 | def equals_hostname_record(self, status): |
| 77 | """Compares this object to a recorded status. |
Chris Masone | f63576d | 2012-06-29 11:13:31 -0700 | [diff] [blame] | 78 | |
Chris Masone | 6ea0cad | 2012-07-02 09:43:36 -0700 | [diff] [blame^] | 79 | Expects the test name field of |status| to contain |self.hostname|. |
| 80 | """ |
| 81 | return (self.status == status._status and |
| 82 | self.hostname in status._test_name and |
| 83 | self.reason == status._reason) |