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.
10 from environment_wrappers
import CreateUrlFetcher
11 from extensions_paths
import (
12 ARTICLES_TEMPLATES
, CHROME_EXTENSIONS
, DOCS
, JSON_TEMPLATES
,
14 from fake_fetchers
import ConfigureFakeFetchers
15 from file_system
import FileNotFoundError
16 from rietveld_patcher
import RietveldPatcher
17 from test_util
import Server2Path
21 def _PrefixWith(prefix
, lst
):
22 return [posixpath
.join(prefix
, item
) for item
in lst
]
25 class RietveldPatcherTest(unittest
.TestCase
):
27 ConfigureFakeFetchers()
28 self
._patcher
= RietveldPatcher(
30 CreateUrlFetcher(url_constants
.CODEREVIEW_SERVER
))
32 def _ReadLocalFile(self
, filename
):
33 with
open(Server2Path('test_data',
39 def _ApplySingle(self
, path
):
40 return self
._patcher
.Apply([path
], None).Get()[path
]
42 def testGetVersion(self
):
43 self
.assertEqual(self
._patcher
.GetVersion(), '22002')
45 def testGetPatchedFiles(self
):
46 added
, deleted
, modified
= self
._patcher
.GetPatchedFiles()
49 _PrefixWith(DOCS
, ['examples/test',
50 'templates/articles/test_foo.html',
51 'templates/public/extensions/test_foo.html']))
52 self
.assertEqual(deleted
,
53 ['%sextensions/runtime.html' % PUBLIC_TEMPLATES
])
56 _PrefixWith(CHROME_EXTENSIONS
,
58 'docs/templates/json/extensions_sidenav.json',
62 article_path
= '%stest_foo.html' % ARTICLES_TEMPLATES
64 # Apply to an added file.
66 self
._ReadLocalFile
('test_foo.html'),
67 self
._ApplySingle
('%sextensions/test_foo.html' % PUBLIC_TEMPLATES
))
69 # Apply to a modified file.
71 self
._ReadLocalFile
('extensions_sidenav.json'),
72 self
._ApplySingle
('%sextensions_sidenav.json' % JSON_TEMPLATES
))
74 # Applying to a deleted file doesn't throw exceptions. It just returns
76 # self.assertRaises(FileNotFoundError, self._ApplySingle,
77 # 'docs/templates/public/extensions/runtime.html')
79 # Apply to an unknown file.
80 self
.assertRaises(FileNotFoundError
, self
._ApplySingle
, 'not_existing')
82 if __name__
== '__main__':