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 appengine_url_fetcher
import AppEngineUrlFetcher
11 from extensions_paths
import (
12 ARTICLES_TEMPLATES
, EXTENSIONS
, DOCS
, JSON_TEMPLATES
, PUBLIC_TEMPLATES
)
13 from fake_fetchers
import ConfigureFakeFetchers
14 from file_system
import FileNotFoundError
15 from rietveld_patcher
import RietveldPatcher
19 def _PrefixWith(prefix
, lst
):
20 return [posixpath
.join(prefix
, item
) for item
in lst
]
23 class RietveldPatcherTest(unittest
.TestCase
):
25 ConfigureFakeFetchers()
26 self
._patcher
= RietveldPatcher(
28 AppEngineUrlFetcher(url_constants
.CODEREVIEW_SERVER
))
30 def _ReadLocalFile(self
, filename
):
31 with
open(os
.path
.join(sys
.path
[0],
38 def _ApplySingle(self
, path
):
39 return self
._patcher
.Apply([path
], None).Get()[path
]
41 def testGetVersion(self
):
42 self
.assertEqual(self
._patcher
.GetVersion(), '22002')
44 def testGetPatchedFiles(self
):
45 added
, deleted
, modified
= self
._patcher
.GetPatchedFiles()
48 _PrefixWith(DOCS
, ['examples/test',
49 'templates/articles/test_foo.html',
50 'templates/public/extensions/test_foo.html']))
51 self
.assertEqual(deleted
,
52 ['%s/extensions/runtime.html' % PUBLIC_TEMPLATES
])
55 _PrefixWith(EXTENSIONS
, ['api/test.json',
56 'docs/templates/json/extensions_sidenav.json',
60 article_path
= '%s/test_foo.html' % ARTICLES_TEMPLATES
62 # Apply to an added file.
64 self
._ReadLocalFile
('test_foo.html'),
65 self
._ApplySingle
('%s/extensions/test_foo.html' % PUBLIC_TEMPLATES
))
67 # Apply to a modified file.
69 self
._ReadLocalFile
('extensions_sidenav.json'),
70 self
._ApplySingle
('%s/extensions_sidenav.json' % JSON_TEMPLATES
))
72 # Applying to a deleted file doesn't throw exceptions. It just returns
74 # self.assertRaises(FileNotFoundError, self._ApplySingle,
75 # 'docs/templates/public/extensions/runtime.html')
77 # Apply to an unknown file.
78 self
.assertRaises(FileNotFoundError
, self
._ApplySingle
, 'not_existing')
80 if __name__
== '__main__':