test_patcher.py revision a93a17c8d99d686bd4a1511e5504e5e6cc9fcadf
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.
4
5from future import Future
6from patcher import Patcher
7
8class TestPatcher(Patcher):
9  def __init__(self, version, patched_files, patch_data, assert_binary=False):
10    self._version = version
11    self._patched_files = patched_files
12    self._patch_data = patch_data
13    self._assert_binary = assert_binary
14
15    self.get_version_count = 0
16    self.get_patched_files_count = 0
17    self.apply_count = 0
18
19  def GetVersion(self):
20    self.get_version_count += 1
21    return self._version
22
23  def GetPatchedFiles(self, version=None):
24    self.get_patched_files_count += 1
25    return self._patched_files
26
27  def Apply(self, paths, file_system, binary, version=None):
28    if self._assert_binary:
29      assert binary
30    self.apply_count += 1
31    try:
32      return Future(value=dict((path, self._patch_data[path])
33                               for path in paths))
34    except KeyError:
35      raise FileNotFoundError('One of %s is deleted in the patch.' % paths)
36