diff options
Diffstat (limited to 'bestflags/mock_task.py')
-rw-r--r-- | bestflags/mock_task.py | 125 |
1 files changed, 63 insertions, 62 deletions
diff --git a/bestflags/mock_task.py b/bestflags/mock_task.py index 6de2b35c..e25daeba 100644 --- a/bestflags/mock_task.py +++ b/bestflags/mock_task.py @@ -1,4 +1,4 @@ -# Copyright (c) 2013 The Chromium OS Authors. All rights reserved. +# Copyright 2013 The ChromiumOS Authors # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. """This module defines the common mock tasks used by various unit tests. @@ -6,87 +6,88 @@ Part of the Chrome build flags optimization. """ -__author__ = 'yuhenglong@google.com (Yuheng Long)' +__author__ = "yuhenglong@google.com (Yuheng Long)" # Pick an integer at random. POISONPILL = 975 class MockTask(object): - """This class emulates an actual task. - - It does not do the actual work, but simply returns the result as given when - this task is constructed. - """ - - def __init__(self, stage, identifier, cost=0): - """Set up the results for this task. - - Args: - stage: the stage of this test is in. - identifier: the identifier of this task. - cost: the mock cost of this task. - - The _cost field stored the cost. Once this task is performed, i.e., by - calling the work method or by setting the result from other task, the - _cost field will have this cost. The stage field verifies that the module - being tested and the unitest are in the same stage. If the unitest does - not care about cost of this task, the cost parameter should be leaved - blank. + """This class emulates an actual task. + + It does not do the actual work, but simply returns the result as given when + this task is constructed. """ - self._identifier = identifier - self._cost = cost - self._stage = stage + def __init__(self, stage, identifier, cost=0): + """Set up the results for this task. + + Args: + stage: the stage of this test is in. + identifier: the identifier of this task. + cost: the mock cost of this task. + + The _cost field stored the cost. Once this task is performed, i.e., by + calling the work method or by setting the result from other task, the + _cost field will have this cost. The stage field verifies that the module + being tested and the unitest are in the same stage. If the unitest does + not care about cost of this task, the cost parameter should be leaved + blank. + """ - # Indicate that this method has not been performed yet. - self._performed = False + self._identifier = identifier + self._cost = cost + self._stage = stage - def __eq__(self, other): - if isinstance(other, MockTask): - return (self._identifier == other.GetIdentifier(self._stage) and - self._cost == other.GetResult(self._stage)) - return False + # Indicate that this method has not been performed yet. + self._performed = False - def GetIdentifier(self, stage): - assert stage == self._stage - return self._identifier + def __eq__(self, other): + if isinstance(other, MockTask): + return self._identifier == other.GetIdentifier( + self._stage + ) and self._cost == other.GetResult(self._stage) + return False - def SetResult(self, stage, cost): - assert stage == self._stage - self._cost = cost - self._performed = True + def GetIdentifier(self, stage): + assert stage == self._stage + return self._identifier - def Work(self, stage): - assert stage == self._stage - self._performed = True + def SetResult(self, stage, cost): + assert stage == self._stage + self._cost = cost + self._performed = True - def GetResult(self, stage): - assert stage == self._stage - return self._cost + def Work(self, stage): + assert stage == self._stage + self._performed = True - def Done(self, stage): - """Indicates whether the task has been performed.""" + def GetResult(self, stage): + assert stage == self._stage + return self._cost - assert stage == self._stage - return self._performed + def Done(self, stage): + """Indicates whether the task has been performed.""" - def LogSteeringCost(self): - pass + assert stage == self._stage + return self._performed + + def LogSteeringCost(self): + pass class IdentifierMockTask(MockTask): - """This class defines the mock task that does not consider the cost. + """This class defines the mock task that does not consider the cost. - The task instances will be inserted into a set. Therefore the hash and the - equal methods are overridden. The unittests that compares identities of the - tasks for equality can use this mock task instead of the base mock tack. - """ + The task instances will be inserted into a set. Therefore the hash and the + equal methods are overridden. The unittests that compares identities of the + tasks for equality can use this mock task instead of the base mock tack. + """ - def __hash__(self): - return self._identifier + def __hash__(self): + return self._identifier - def __eq__(self, other): - if isinstance(other, MockTask): - return self._identifier == other.GetIdentifier(self._stage) - return False + def __eq__(self, other): + if isinstance(other, MockTask): + return self._identifier == other.GetIdentifier(self._stage) + return False |