Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(65)

Side by Side Diff: chrome/common/extensions/docs/server2/patched_file_system_test.py

Issue 14125010: Docserver: Add support for viewing docs with a codereview patch applied (Closed) Base URL: https://src.chromium.org/svn/trunk/src/
Patch Set: Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
Property Changes:
Added: svn:eol-style
+ LF
Added: svn:executable
+ *
OLDNEW
(Empty)
1 #!/usr/bin/env python
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.
5
6 import os
7 import sys
8 import unittest
9 from appengine_url_fetcher import AppEngineUrlFetcher
10 from appengine_wrappers import files
11 from fake_fetchers import ConfigureFakeFetchers
12 from fake_url_fetcher import FakeUrlFetcher, _Response
13 from file_system import FileNotFoundError, StatInfo
14 from future import Future
15 from object_store_creator import ObjectStoreCreator
16 from patched_file_system import PatchedFileSystem, Patcher
17 from subversion_file_system import SubversionFileSystem
18 import url_constants
19
20 class TestPatcher(Patcher):
21 def GetVersion(self):
22 return '1'
not at google - send to devlin 2013/05/03 19:12:22 ditto not used
方觉(Fang Jue) 2013/05/04 02:05:41 But GetVersion must be implemented.
not at google - send to devlin 2013/05/04 06:47:43 Getting ahead of myself.
23
24 def GetPatchedFiles(self):
25 return (
26 # Added files
27 [
28 'test4.txt',
29 'list/file7.html',
30 'newdir/sub/1.html',
31 ],
32 # Deleted files
33 [
34 'test3.txt',
35 'list/file1.html',
36 # These should be silently ignored instead of errors.
37 'not_existing_foo',
38 'list/not_existing_foo',
39 ],
40 # Modified files
41 [
42 'test1.txt',
43 'test2.txt',
44 ])
45
46 def Apply(self, paths, file_system, binary):
47 patch_data = {
48 'test1.txt': 'Test1 is patched.\n',
49 'test2.txt': 'Test2 is also patched.\n',
50 'test4.txt': 'Test4 is added.\n',
51 'list/file6.html': '',
52 'newdir/sub/1.html': '',
53 }
54
55 value = {}
56 for path in paths:
57 if patch_data.get(path) is not None:
58 value[path] = patch_data[path]
59 else:
60 raise FileNotFoundError('%s is deleted in the patch.' % path)
61 return Future(value=value)
62
63 class FakeStatFetcher(FakeUrlFetcher):
64 def Fetch(self, url):
65 assert url.endswith('/')
66 try:
67 return FakeUrlFetcher.Fetch(self, url + 'stat')
68 except IOError:
69 # FakeUrlFetcher throws IOError when the file was not found. But
70 # ViewVC server returns 404 in this case.
71 result = _Response()
72 result.status_code = 404
73 return result
74
75 class PatchedFileSystemTest(unittest.TestCase):
76 def setUp(self):
77 ConfigureFakeFetchers(os.path.join(sys.path[0], os.pardir))
not at google - send to devlin 2013/05/03 19:12:22 it should be possible to write this test using pur
78 fetcher = FakeUrlFetcher(os.path.join(sys.path[0],
79 'test_data',
80 'file_system'))
81 stat_fetcher = FakeStatFetcher(os.path.join(sys.path[0],
82 'test_data',
83 'file_system_stat'))
84 self._svn_file_system = SubversionFileSystem(fetcher, stat_fetcher)
85 self._patcher = TestPatcher()
86 self._file_system = PatchedFileSystem(self._svn_file_system,
87 self._patcher)
88
89 def testRead(self):
90 expected = {
91 'test1.txt': 'Test1 is patched.\n',
92 'test2.txt': 'Test2 is also patched.\n',
93 'test4.txt': 'Test4 is added.\n',
94 'newdir/sub/1.html': '',
95 }
96 self.assertEqual(
97 expected,
98 self._file_system.Read(expected.keys()).Get())
99
100 self.assertRaises(FileNotFoundError, self._file_system.ReadSingle,
101 'test3.txt')
102
103 def testReadDir(self):
104 self.assertEqual(sorted(self._file_system.ReadSingle('list/')),
105 sorted(set(self._svn_file_system.ReadSingle('list/')) |
106 {'file7.html'} - {'file1.html'}))
107
108 def testStat(self):
109 version = 'patched_%s' % self._patcher.GetVersion()
110
111 # Stat an unmodified file.
112 self.assertEqual(self._file_system.Stat('list/file6.html').version,
113 '147471')
114
115 # Stat an unmodified directory.
116 self.assertEqual(self._file_system.Stat('list/dir/'),
117 self._svn_file_system.Stat('list/dir/'))
118
119 # Stat a modified directory.
120 list_stat = self._svn_file_system.Stat('list/')
121 list_stat.version = version
122 list_stat.child_versions.update({'file7.html': version})
123 del list_stat.child_versions['file1.html']
124 self.assertEqual(self._file_system.Stat('list/'), list_stat)
125
126 # Stat an added directory.
127 self.assertEqual(self._file_system.Stat('newdir/'),
128 StatInfo(version, {
129 'sub/': version,
130 }))
131
132 # Stat files removed in the patch.
133 self.assertRaises(FileNotFoundError,self._file_system.Stat,
134 'list/file1.html')
135
136 # Stat files that don't exist in either before or after patching.
137 self.assertRaises(FileNotFoundError, self._file_system.Stat,
138 'list/not_existing_file')
139 self.assertRaises(FileNotFoundError, self._file_system.Stat,
140 'not_existing_dir/')
141
142 if __name__ == '__main__':
143 unittest.main()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698