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):
10    self._version = version
11    self._patched_files = patched_files
12    self._patch_data = patch_data
13
14    self.get_version_count = 0
15    self.get_patched_files_count = 0
16    self.apply_count = 0
17
18  def GetVersion(self):
19    self.get_version_count += 1
20    return self._version
21
22  def GetPatchedFiles(self, version=None):
23    self.get_patched_files_count += 1
24    return self._patched_files
25
26  def Apply(self, paths, file_system, version=None):
27    self.apply_count += 1
28    try:
29      return Future(value=dict((path, self._patch_data[path])
30                               for path in paths))
31    except KeyError:
32      raise FileNotFoundError('One of %s is deleted in the patch.' % paths)
33
34  def GetIdentity(self):
35    return self.__class__.__name__
36