2 # Copyright 2013 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file.
9 from appengine_url_fetcher import AppEngineUrlFetcher
10 from fake_fetchers import ConfigureFakeFetchers
11 from file_system import FileNotFoundError
12 from rietveld_patcher import RietveldPatcher
13 from svn_constants import EXTENSIONS_PATH
16 class RietveldPatcherTest(unittest.TestCase):
18 ConfigureFakeFetchers()
19 self._patcher = RietveldPatcher(
22 AppEngineUrlFetcher(url_constants.CODEREVIEW_SERVER))
24 def _ReadLocalFile(self, filename):
25 with open(os.path.join(sys.path[0],
32 def _ApplySingle(self, path, binary=False):
33 return self._patcher.Apply([path], None, binary).Get()[path]
35 def testGetVersion(self):
36 self.assertEqual(self._patcher.GetVersion(), '22002')
38 def testGetPatchedFiles(self):
39 added, deleted, modified = self._patcher.GetPatchedFiles()
40 self.assertEqual(sorted(added),
42 u'docs/templates/articles/test_foo.html',
43 u'docs/templates/public/extensions/test_foo.html']))
44 self.assertEqual(sorted(deleted),
46 u'docs/templates/public/extensions/runtime.html']))
47 self.assertEqual(sorted(modified),
50 u'docs/templates/json/extensions_sidenav.json']))
53 article_path = 'docs/templates/articles/test_foo.html'
55 # Make sure RietveldPatcher handles |binary| correctly.
56 self.assertTrue(isinstance(self._ApplySingle(article_path, True), str),
57 'Expected result is binary. It was text.')
58 self.assertTrue(isinstance(self._ApplySingle(article_path), unicode),
59 'Expected result is text. It was binary.')
61 # Apply to an added file.
63 self._ReadLocalFile('test_foo.html'),
65 'docs/templates/public/extensions/test_foo.html'))
67 # Apply to a modified file.
69 self._ReadLocalFile('extensions_sidenav.json'),
71 'docs/templates/json/extensions_sidenav.json'))
73 # Applying to a deleted file doesn't throw exceptions. It just returns
75 # self.assertRaises(FileNotFoundError, self._ApplySingle,
76 # 'docs/templates/public/extensions/runtime.html')
78 # Apply to an unknown file.
79 self.assertRaises(FileNotFoundError, self._ApplySingle, 'not_existing')
81 if __name__ == '__main__':