summaryrefslogtreecommitdiffstats
path: root/chrome/common/extensions/docs/server2/test_patcher.py
blob: 6c4b906aa1332e36a4a323acf7505f224f5baa74 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# Copyright 2013 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

from future import Future
from patcher import Patcher

class TestPatcher(Patcher):
  def __init__(self, version, patched_files, patch_data):
    self._version = version
    self._patched_files = patched_files
    self._patch_data = patch_data

    self.get_version_count = 0
    self.get_patched_files_count = 0
    self.apply_count = 0

  def GetVersion(self):
    self.get_version_count += 1
    return self._version

  def GetPatchedFiles(self, version=None):
    self.get_patched_files_count += 1
    return self._patched_files

  def Apply(self, paths, file_system, version=None):
    self.apply_count += 1
    try:
      return Future(value=dict((path, self._patch_data[path])
                               for path in paths))
    except KeyError:
      raise FileNotFoundError('One of %s is deleted in the patch.' % paths)

  def GetIdentity(self):
    return self.__class__.__name__