1 # Copyright 2013 The Chromium 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.
7 """Verifies that the current machine states match the expectation."""
9 def VerifyInput(self
, verifier_input
, variable_expander
):
10 """Verifies that the current machine states match |verifier_input|.
13 verifier_input: An input to the verifier. It is a dictionary where each
14 key is an expectation name and the associated value is an expectation
15 dictionary. The expectation dictionary may contain an optional
16 'condition' property, a string that determines whether the expectation
17 should be verified. Each subclass can specify a different expectation
18 name and expectation dictionary.
19 variable_expander: A VariableExpander object.
21 for expectation_name
, expectation
in verifier_input
.iteritems():
22 if 'condition' in expectation
:
23 condition
= variable_expander
.Expand(expectation
['condition'])
24 if not self
._EvaluateCondition
(condition
):
26 self
._VerifyExpectation
(expectation_name
, expectation
, variable_expander
)
28 def _VerifyExpectation(self
, expectation_name
, expectation
,
30 """Verifies that the current machine states match |verifier_input|.
32 This is an abstract method for subclasses to override.
35 expectation_name: An expectation name. Each subclass can specify a
36 different expectation name format.
37 expectation: An expectation dictionary. Each subclass can specify a
38 different expectation dictionary format.
39 variable_expander: A VariableExpander object.
41 raise NotImplementedError()
43 def _EvaluateCondition(self
, condition
):
44 """Evaluates |condition| using eval().
47 condition: A condition string.
50 The result of the evaluated condition.
52 return eval(condition
, {'__builtins__': None}, None)