Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 # Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 import os | 5 import os |
| 6 | 6 |
| 7 import verifier | 7 import verifier |
| 8 | 8 |
| 9 | 9 |
| 10 class FileVerifier(verifier.Verifier): | 10 class FileVerifier(verifier.Verifier): |
| 11 """Verifies that the current files match the expectation dictionaries.""" | 11 """Verifies that the current files match the expectation dictionaries.""" |
| 12 | 12 |
| 13 def __init__(self): | |
| 14 self._file_path = None | |
| 15 self._file_exists = None | |
| 16 | |
| 13 def _VerifyExpectation(self, expectation_name, expectation, | 17 def _VerifyExpectation(self, expectation_name, expectation, |
| 14 variable_expander): | 18 variable_expander): |
| 15 """Overridden from verifier.Verifier. | 19 """Overridden from verifier.Verifier. |
| 16 | 20 |
| 17 This method will throw an AssertionError if file state doesn't match the | 21 This method will throw an AssertionError if file state doesn't match the |
| 18 |expectation|. | 22 |expectation|. |
| 19 | 23 |
| 20 Args: | 24 Args: |
| 21 expectation_name: Path to the file being verified. It is expanded using | 25 expectation_name: Path to the file being verified. It is expanded using |
| 22 Expand. | 26 Expand. |
| 23 expectation: A dictionary with the following key and value: | 27 expectation: A dictionary with the following key and value: |
| 24 'exists' a boolean indicating whether the file should exist. | 28 'exists' a boolean indicating whether the file should exist. |
| 25 variable_expander: A VariableExpander object. | 29 variable_expander: A VariableExpander object. |
| 26 """ | 30 """ |
| 27 file_path = variable_expander.Expand(expectation_name) | 31 self._file_path = variable_expander.Expand(expectation_name) |
|
grt (UTC plus 2)
2017/03/14 09:19:44
why store state in the verifier? one instance is u
| |
| 28 file_exists = os.path.exists(file_path) | 32 self._file_exists = os.path.exists(self._file_path) |
| 29 assert expectation['exists'] == file_exists, \ | 33 self._Assert(expectation['exists'] == self._file_exists, |
| 30 ('File %s exists' % file_path) if file_exists else \ | 34 ('File %s exists' % self._file_path) if self._file_exists \ |
| 31 ('File %s is missing' % file_path) | 35 else ('File %s is missing' % self._file_path)) |
| OLD | NEW |