OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 import os | 6 import os |
7 import posixpath | 7 import posixpath |
8 import sys | 8 import sys |
9 import unittest | 9 import unittest |
10 from appengine_url_fetcher import AppEngineUrlFetcher | 10 from environment_wrappers import CreateUrlFetcher |
11 from extensions_paths import ( | 11 from extensions_paths import ( |
12 ARTICLES_TEMPLATES, CHROME_EXTENSIONS, DOCS, JSON_TEMPLATES, | 12 ARTICLES_TEMPLATES, CHROME_EXTENSIONS, DOCS, JSON_TEMPLATES, |
13 PUBLIC_TEMPLATES) | 13 PUBLIC_TEMPLATES) |
14 from fake_fetchers import ConfigureFakeFetchers | 14 from fake_fetchers import ConfigureFakeFetchers |
15 from file_system import FileNotFoundError | 15 from file_system import FileNotFoundError |
16 from rietveld_patcher import RietveldPatcher | 16 from rietveld_patcher import RietveldPatcher |
17 from test_util import Server2Path | 17 from test_util import Server2Path |
18 import url_constants | 18 import url_constants |
19 | 19 |
20 | 20 |
21 def _PrefixWith(prefix, lst): | 21 def _PrefixWith(prefix, lst): |
22 return [posixpath.join(prefix, item) for item in lst] | 22 return [posixpath.join(prefix, item) for item in lst] |
23 | 23 |
24 | 24 |
25 class RietveldPatcherTest(unittest.TestCase): | 25 class RietveldPatcherTest(unittest.TestCase): |
26 def setUp(self): | 26 def setUp(self): |
27 ConfigureFakeFetchers() | 27 ConfigureFakeFetchers() |
28 self._patcher = RietveldPatcher( | 28 self._patcher = RietveldPatcher( |
29 '14096030', | 29 '14096030', |
30 AppEngineUrlFetcher(url_constants.CODEREVIEW_SERVER)) | 30 CreateUrlFetcher(url_constants.CODEREVIEW_SERVER)) |
31 | 31 |
32 def _ReadLocalFile(self, filename): | 32 def _ReadLocalFile(self, filename): |
33 with open(Server2Path('test_data', | 33 with open(Server2Path('test_data', |
34 'rietveld_patcher', | 34 'rietveld_patcher', |
35 'expected', | 35 'expected', |
36 filename), 'r') as f: | 36 filename), 'r') as f: |
37 return f.read() | 37 return f.read() |
38 | 38 |
39 def _ApplySingle(self, path): | 39 def _ApplySingle(self, path): |
40 return self._patcher.Apply([path], None).Get()[path] | 40 return self._patcher.Apply([path], None).Get()[path] |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 # Applying to a deleted file doesn't throw exceptions. It just returns | 74 # Applying to a deleted file doesn't throw exceptions. It just returns |
75 # empty content. | 75 # empty content. |
76 # self.assertRaises(FileNotFoundError, self._ApplySingle, | 76 # self.assertRaises(FileNotFoundError, self._ApplySingle, |
77 # 'docs/templates/public/extensions/runtime.html') | 77 # 'docs/templates/public/extensions/runtime.html') |
78 | 78 |
79 # Apply to an unknown file. | 79 # Apply to an unknown file. |
80 self.assertRaises(FileNotFoundError, self._ApplySingle, 'not_existing') | 80 self.assertRaises(FileNotFoundError, self._ApplySingle, 'not_existing') |
81 | 81 |
82 if __name__ == '__main__': | 82 if __name__ == '__main__': |
83 unittest.main() | 83 unittest.main() |
OLD | NEW |