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

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

Issue 13599004: Fix some low hanging inefficiencies in the docs server (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 7 years, 8 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 | Annotate | Revision Log
OLDNEW
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 from compiled_file_system import CompiledFileSystem 6 from compiled_file_system import CompiledFileSystem
7 from copy import deepcopy 7 from copy import deepcopy
8 from file_system import FileNotFoundError 8 from file_system import FileNotFoundError
9 from test_file_system import TestFileSystem 9 from test_file_system import TestFileSystem
10 from test_object_store import TestObjectStore 10 from test_object_store import TestObjectStore
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 def testIdentityFromFile(self): 42 def testIdentityFromFile(self):
43 compiled_fs = _CreateFactory().GetOrCreateIdentity() 43 compiled_fs = _CreateFactory().GetOrCreateIdentity()
44 self.assertEqual('404.html contents', compiled_fs.GetFromFile('404.html')) 44 self.assertEqual('404.html contents', compiled_fs.GetFromFile('404.html'))
45 self.assertEqual('a11y.html contents', 45 self.assertEqual('a11y.html contents',
46 compiled_fs.GetFromFile('apps/a11y.html')) 46 compiled_fs.GetFromFile('apps/a11y.html'))
47 self.assertEqual('file.html contents', 47 self.assertEqual('file.html contents',
48 compiled_fs.GetFromFile('/apps/fakedir/file.html')) 48 compiled_fs.GetFromFile('/apps/fakedir/file.html'))
49 49
50 def testIdentityFromFileListing(self): 50 def testIdentityFromFileListing(self):
51 compiled_fs = _CreateFactory().GetOrCreateIdentity() 51 compiled_fs = _CreateFactory().GetOrCreateIdentity()
52 self.assertEqual({'404.html', 'apps/a11y.html', 'apps/about_apps.html', 52 self.assertEqual(set(('404.html',
53 'apps/fakedir/file.html', 53 'apps/a11y.html',
54 'extensions/activeTab.html', 'extensions/alarms.html'}, 54 'apps/about_apps.html',
55 'apps/fakedir/file.html',
56 'extensions/activeTab.html',
57 'extensions/alarms.html')),
55 set(compiled_fs.GetFromFileListing('/'))) 58 set(compiled_fs.GetFromFileListing('/')))
56 self.assertEqual({'a11y.html', 'about_apps.html', 'fakedir/file.html'}, 59 self.assertEqual(set(('a11y.html', 'about_apps.html', 'fakedir/file.html')),
57 set(compiled_fs.GetFromFileListing('apps/'))) 60 set(compiled_fs.GetFromFileListing('apps/')))
58 self.assertEqual({'file.html'}, 61 self.assertEqual(set(('file.html',)),
59 set(compiled_fs.GetFromFileListing('apps/fakedir'))) 62 set(compiled_fs.GetFromFileListing('apps/fakedir')))
60 63
61 def testPopulateNamespace(self): 64 def testPopulateNamespace(self):
62 def CheckNamespace(expected_file, expected_list, fs): 65 def CheckNamespace(expected_file, expected_list, fs):
63 self.assertEqual(expected_file, fs._file_object_store.namespace) 66 self.assertEqual(expected_file, fs._file_object_store.namespace)
64 self.assertEqual(expected_list, fs._list_object_store.namespace) 67 self.assertEqual(expected_list, fs._list_object_store.namespace)
65 factory = _CreateFactory() 68 factory = _CreateFactory()
66 f = lambda x: x 69 f = lambda x: x
67 CheckNamespace('CompiledFileSystem/CompiledFileSystemTest/file', 70 CheckNamespace('CompiledFileSystem/CompiledFileSystemTest/file',
68 'CompiledFileSystem/CompiledFileSystemTest/list', 71 'CompiledFileSystem/CompiledFileSystemTest/list',
(...skipping 16 matching lines...) Expand all
85 self.assertEqual('ZZZZZZZZzzzzzzzzzzzzzzzzz', 88 self.assertEqual('ZZZZZZZZzzzzzzzzzzzzzzzzz',
86 compiled_fs.GetFromFile('404.html')) 89 compiled_fs.GetFromFile('404.html'))
87 self.assertEqual('ZZZZZZZZZZZZZZzzzzzzzzzzzzzzzzzz', 90 self.assertEqual('ZZZZZZZZZZZZZZzzzzzzzzzzzzzzzzzz',
88 compiled_fs.GetFromFile('apps/a11y.html')) 91 compiled_fs.GetFromFile('apps/a11y.html'))
89 self.assertEqual('ZZZZZZZZZZZZZZZZZZZZZZZzzzzzzzzzzzzzzzzzz', 92 self.assertEqual('ZZZZZZZZZZZZZZZZZZZZZZZzzzzzzzzzzzzzzzzzz',
90 compiled_fs.GetFromFile('/apps/fakedir/file.html')) 93 compiled_fs.GetFromFile('/apps/fakedir/file.html'))
91 94
92 def testCaching(self): 95 def testCaching(self):
93 compiled_fs = _CreateFactory().GetOrCreateIdentity() 96 compiled_fs = _CreateFactory().GetOrCreateIdentity()
94 self.assertEqual('404.html contents', compiled_fs.GetFromFile('404.html')) 97 self.assertEqual('404.html contents', compiled_fs.GetFromFile('404.html'))
95 self.assertEqual({'file.html'}, 98 self.assertEqual(set(('file.html',)),
96 set(compiled_fs.GetFromFileListing('apps/fakedir'))) 99 set(compiled_fs.GetFromFileListing('apps/fakedir')))
97 100
98 compiled_fs._file_system._obj['404.html'] = 'boom' 101 compiled_fs._file_system._obj['404.html'] = 'boom'
99 compiled_fs._file_system._obj['apps']['fakedir']['boom.html'] = 'blam' 102 compiled_fs._file_system._obj['apps']['fakedir']['boom.html'] = 'blam'
100 self.assertEqual('404.html contents', compiled_fs.GetFromFile('404.html')) 103 self.assertEqual('404.html contents', compiled_fs.GetFromFile('404.html'))
101 self.assertEqual({'file.html'}, 104 self.assertEqual(set(('file.html',)),
102 set(compiled_fs.GetFromFileListing('apps/fakedir'))) 105 set(compiled_fs.GetFromFileListing('apps/fakedir')))
103 106
104 compiled_fs._file_system.IncrementStat() 107 compiled_fs._file_system.IncrementStat()
105 self.assertEqual('boom', compiled_fs.GetFromFile('404.html')) 108 self.assertEqual('boom', compiled_fs.GetFromFile('404.html'))
106 self.assertEqual({'file.html', 'boom.html'}, 109 self.assertEqual(set(('file.html', 'boom.html')),
107 set(compiled_fs.GetFromFileListing('apps/fakedir'))) 110 set(compiled_fs.GetFromFileListing('apps/fakedir')))
108 111
109 def testFailures(self): 112 def testFailures(self):
110 compiled_fs = _CreateFactory().GetOrCreateIdentity() 113 compiled_fs = _CreateFactory().GetOrCreateIdentity()
111 self.assertRaises(FileNotFoundError, compiled_fs.GetFromFile, '405.html') 114 self.assertRaises(FileNotFoundError, compiled_fs.GetFromFile, '405.html')
112 # TODO(kalman): would be nice to test this fails since apps/ is a dir. 115 # TODO(kalman): would be nice to test this fails since apps/ is a dir.
113 compiled_fs.GetFromFile('apps/') 116 compiled_fs.GetFromFile('apps/')
114 #self.assertRaises(SomeError, compiled_fs.GetFromFile, 'apps/') 117 #self.assertRaises(SomeError, compiled_fs.GetFromFile, 'apps/')
115 self.assertRaises(FileNotFoundError, 118 self.assertRaises(FileNotFoundError,
116 compiled_fs.GetFromFileListing, 'nodir/') 119 compiled_fs.GetFromFileListing, 'nodir/')
117 # TODO(kalman): likewise, not a FileNotFoundError. 120 # TODO(kalman): likewise, not a FileNotFoundError.
118 self.assertRaises(FileNotFoundError, 121 self.assertRaises(FileNotFoundError,
119 compiled_fs.GetFromFileListing, '404.html') 122 compiled_fs.GetFromFileListing, '404.html')
120 123
121 if __name__ == '__main__': 124 if __name__ == '__main__':
122 unittest.main() 125 unittest.main()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698