Chromium Code Reviews| 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 functools | 6 import functools |
| 7 import os | 7 import os |
| 8 | 8 |
| 9 from compiled_file_system import CompiledFileSystem | 9 from compiled_file_system import Cache, CompiledFileSystem |
| 10 from copy import deepcopy | 10 from copy import deepcopy |
| 11 from environment import GetAppVersion | 11 from environment import GetAppVersion |
| 12 from file_system import FileNotFoundError | 12 from file_system import FileNotFoundError |
| 13 from mock_file_system import MockFileSystem | 13 from mock_file_system import MockFileSystem |
| 14 from object_store_creator import ObjectStoreCreator | 14 from object_store_creator import ObjectStoreCreator |
| 15 from test_file_system import TestFileSystem | 15 from test_file_system import TestFileSystem |
| 16 from test_object_store import TestObjectStore | 16 from test_object_store import TestObjectStore |
| 17 import unittest | 17 import unittest |
| 18 | 18 |
| 19 _TEST_DATA = { | 19 _TEST_DATA = { |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 114 self.assertEqual(['file',], | 114 self.assertEqual(['file',], |
| 115 compiled_fs.GetFromFileListing('apps/fakedir/').Get()) | 115 compiled_fs.GetFromFileListing('apps/fakedir/').Get()) |
| 116 self.assertEqual(['deeper/deepest', 'deepfile'], | 116 self.assertEqual(['deeper/deepest', 'deepfile'], |
| 117 sorted(compiled_fs.GetFromFileListing( | 117 sorted(compiled_fs.GetFromFileListing( |
| 118 'apps/deepdir/').Get())) | 118 'apps/deepdir/').Get())) |
| 119 self.assertEqual(['deepest'], | 119 self.assertEqual(['deepest'], |
| 120 compiled_fs.GetFromFileListing( | 120 compiled_fs.GetFromFileListing( |
| 121 'apps/deepdir/deeper/').Get()) | 121 'apps/deepdir/deeper/').Get()) |
| 122 | 122 |
| 123 def testCaching(self): | 123 def testCaching(self): |
| 124 compiled_fs = _GetTestCompiledFsCreator()(identity, CompiledFileSystemTest) | 124 compiled_fs = _GetTestCompiledFsCreator()(Cache(identity), |
|
not at google - send to devlin
2014/08/29 05:00:14
Is there a way to test this new functionality?
ahernandez
2014/08/29 17:20:00
The tests here serve as a sort of regression test.
| |
| 125 CompiledFileSystemTest) | |
| 125 self.assertEqual('404.html contents', | 126 self.assertEqual('404.html contents', |
| 126 compiled_fs.GetFromFile('404.html').Get()) | 127 compiled_fs.GetFromFile('404.html').Get()) |
| 127 self.assertEqual(set(('file.html',)), | 128 self.assertEqual(set(('file.html',)), |
| 128 set(compiled_fs.GetFromFileListing('apps/fakedir/').Get())) | 129 set(compiled_fs.GetFromFileListing('apps/fakedir/').Get())) |
| 129 | 130 |
| 130 compiled_fs._file_system._path_values['404.html'] = 'boom' | 131 compiled_fs._file_system._path_values['404.html'] = 'boom' |
| 131 compiled_fs._file_system._path_values['apps/fakedir/'] = [ | 132 compiled_fs._file_system._path_values['apps/fakedir/'] = [ |
| 132 'file.html', 'boom.html'] | 133 'file.html', 'boom.html'] |
| 133 self.assertEqual('404.html contents', | 134 self.assertEqual('404.html contents', |
| 134 compiled_fs.GetFromFile('404.html').Get()) | 135 compiled_fs.GetFromFile('404.html').Get()) |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 197 self.assertTrue(*mock_fs.CheckAndReset(stat_count=1, | 198 self.assertTrue(*mock_fs.CheckAndReset(stat_count=1, |
| 198 read_count=2, | 199 read_count=2, |
| 199 read_resolve_count=1)) | 200 read_resolve_count=1)) |
| 200 future.Get() | 201 future.Get() |
| 201 self.assertTrue(*mock_fs.CheckAndReset(read_count=2, read_resolve_count=3)) | 202 self.assertTrue(*mock_fs.CheckAndReset(read_count=2, read_resolve_count=3)) |
| 202 | 203 |
| 203 def testSkipNotFound(self): | 204 def testSkipNotFound(self): |
| 204 mock_fs = MockFileSystem(TestFileSystem(_TEST_DATA)) | 205 mock_fs = MockFileSystem(TestFileSystem(_TEST_DATA)) |
| 205 compiled_fs = CompiledFileSystem.Factory( | 206 compiled_fs = CompiledFileSystem.Factory( |
| 206 ObjectStoreCreator.ForTest()).Create( | 207 ObjectStoreCreator.ForTest()).Create( |
| 207 mock_fs, lambda path, contents: contents, type(self)) | 208 mock_fs, Cache(lambda path, contents: contents), type(self)) |
| 208 | 209 |
| 209 future = compiled_fs.GetFromFile('no_file', skip_not_found=True) | 210 future = compiled_fs.GetFromFile('no_file', skip_not_found=True) |
| 210 # If the file doesn't exist, then the file system is not read. | 211 # If the file doesn't exist, then the file system is not read. |
| 211 self.assertTrue(*mock_fs.CheckAndReset(read_count=1, stat_count=1)) | 212 self.assertTrue(*mock_fs.CheckAndReset(read_count=1, stat_count=1)) |
| 212 self.assertEqual(None, future.Get()) | 213 self.assertEqual(None, future.Get()) |
| 213 self.assertTrue(*mock_fs.CheckAndReset(read_resolve_count=1)) | 214 self.assertTrue(*mock_fs.CheckAndReset(read_resolve_count=1)) |
| 214 future = compiled_fs.GetFromFile('no_file', skip_not_found=True) | 215 future = compiled_fs.GetFromFile('no_file', skip_not_found=True) |
| 215 self.assertTrue(*mock_fs.CheckAndReset(stat_count=1)) | 216 self.assertTrue(*mock_fs.CheckAndReset(stat_count=1)) |
| 216 self.assertEqual(None, future.Get()) | 217 self.assertEqual(None, future.Get()) |
| 217 # The result for a non-existent file should still be cached. | 218 # The result for a non-existent file should still be cached. |
| 218 self.assertTrue(*mock_fs.CheckAndReset()) | 219 self.assertTrue(*mock_fs.CheckAndReset()) |
| 219 future = compiled_fs.GetFromFile('no_file') | 220 future = compiled_fs.GetFromFile('no_file') |
| 220 self.assertRaises(FileNotFoundError, future.Get) | 221 self.assertRaises(FileNotFoundError, future.Get) |
| 221 | 222 |
| 222 | 223 |
| 223 if __name__ == '__main__': | 224 if __name__ == '__main__': |
| 224 unittest.main() | 225 unittest.main() |
| OLD | NEW |