| 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 from appengine_wrappers import GetAppVersion | 6 from appengine_wrappers import GetAppVersion |
| 7 from compiled_file_system import CompiledFileSystem | 7 from compiled_file_system import CompiledFileSystem |
| 8 from copy import deepcopy | 8 from copy import deepcopy |
| 9 from file_system import FileNotFoundError | 9 from file_system import FileNotFoundError |
| 10 from object_store_creator import ObjectStoreCreator | 10 from object_store_creator import ObjectStoreCreator |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 }, | 23 }, |
| 24 'extensions': { | 24 'extensions': { |
| 25 'activeTab.html': 'activeTab.html contents', | 25 'activeTab.html': 'activeTab.html contents', |
| 26 'alarms.html': 'alarms.html contents' | 26 'alarms.html': 'alarms.html contents' |
| 27 } | 27 } |
| 28 } | 28 } |
| 29 | 29 |
| 30 def _CreateFactory(): | 30 def _CreateFactory(): |
| 31 return CompiledFileSystem.Factory( | 31 return CompiledFileSystem.Factory( |
| 32 TestFileSystem(deepcopy(_TEST_DATA)), | 32 TestFileSystem(deepcopy(_TEST_DATA)), |
| 33 ObjectStoreCreator('test', | 33 ObjectStoreCreator(start_empty=False, |
| 34 start_empty=False, | |
| 35 store_type=TestObjectStore, | 34 store_type=TestObjectStore, |
| 36 disable_wrappers=True)) | 35 disable_wrappers=True)) |
| 37 | 36 |
| 38 class CompiledFileSystemTest(unittest.TestCase): | 37 class CompiledFileSystemTest(unittest.TestCase): |
| 39 def testIdentityNamespace(self): | 38 def testIdentityNamespace(self): |
| 40 factory = _CreateFactory() | 39 factory = _CreateFactory() |
| 41 compiled_fs = factory.CreateIdentity(CompiledFileSystemTest) | 40 compiled_fs = factory.CreateIdentity(CompiledFileSystemTest) |
| 42 self.assertEqual( | 41 self.assertEqual( |
| 43 'class=CompiledFileSystem&category=CompiledFileSystemTest/file&' | 42 'class=CompiledFileSystem&' |
| 44 'channel=test&app_version=%s' % GetAppVersion(), | 43 'category=CompiledFileSystemTest/TestFileSystem/file&' |
| 44 'app_version=%s' % GetAppVersion(), |
| 45 compiled_fs._file_object_store.namespace) | 45 compiled_fs._file_object_store.namespace) |
| 46 | 46 |
| 47 def testIdentityFromFile(self): | 47 def testIdentityFromFile(self): |
| 48 compiled_fs = _CreateFactory().CreateIdentity(CompiledFileSystemTest) | 48 compiled_fs = _CreateFactory().CreateIdentity(CompiledFileSystemTest) |
| 49 self.assertEqual('404.html contents', compiled_fs.GetFromFile('404.html')) | 49 self.assertEqual('404.html contents', compiled_fs.GetFromFile('404.html')) |
| 50 self.assertEqual('a11y.html contents', | 50 self.assertEqual('a11y.html contents', |
| 51 compiled_fs.GetFromFile('apps/a11y.html')) | 51 compiled_fs.GetFromFile('apps/a11y.html')) |
| 52 self.assertEqual('file.html contents', | 52 self.assertEqual('file.html contents', |
| 53 compiled_fs.GetFromFile('/apps/fakedir/file.html')) | 53 compiled_fs.GetFromFile('/apps/fakedir/file.html')) |
| 54 | 54 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 66 self.assertEqual(set(('file.html',)), | 66 self.assertEqual(set(('file.html',)), |
| 67 set(compiled_fs.GetFromFileListing('apps/fakedir'))) | 67 set(compiled_fs.GetFromFileListing('apps/fakedir'))) |
| 68 | 68 |
| 69 def testPopulateNamespace(self): | 69 def testPopulateNamespace(self): |
| 70 def CheckNamespace(expected_file, expected_list, fs): | 70 def CheckNamespace(expected_file, expected_list, fs): |
| 71 self.assertEqual(expected_file, fs._file_object_store.namespace) | 71 self.assertEqual(expected_file, fs._file_object_store.namespace) |
| 72 self.assertEqual(expected_list, fs._list_object_store.namespace) | 72 self.assertEqual(expected_list, fs._list_object_store.namespace) |
| 73 factory = _CreateFactory() | 73 factory = _CreateFactory() |
| 74 f = lambda x: x | 74 f = lambda x: x |
| 75 CheckNamespace( | 75 CheckNamespace( |
| 76 'class=CompiledFileSystem&category=CompiledFileSystemTest/file&' | 76 'class=CompiledFileSystem&' |
| 77 'channel=test&app_version=%s' % GetAppVersion(), | 77 'category=CompiledFileSystemTest/TestFileSystem/file&' |
| 78 'class=CompiledFileSystem&category=CompiledFileSystemTest/list&' | 78 'app_version=%s' % GetAppVersion(), |
| 79 'channel=test&app_version=%s' % GetAppVersion(), | 79 'class=CompiledFileSystem&' |
| 80 'category=CompiledFileSystemTest/TestFileSystem/list&' |
| 81 'app_version=%s' % GetAppVersion(), |
| 80 factory.Create(f, CompiledFileSystemTest)) | 82 factory.Create(f, CompiledFileSystemTest)) |
| 81 CheckNamespace( | 83 CheckNamespace( |
| 82 'class=CompiledFileSystem&category=CompiledFileSystemTest/foo/file&' | 84 'class=CompiledFileSystem&' |
| 83 'channel=test&app_version=%s' % GetAppVersion(), | 85 'category=CompiledFileSystemTest/TestFileSystem/foo/file&' |
| 84 'class=CompiledFileSystem&category=CompiledFileSystemTest/foo/list&' | 86 'app_version=%s' % GetAppVersion(), |
| 85 'channel=test&app_version=%s' % GetAppVersion(), | 87 'class=CompiledFileSystem&' |
| 88 'category=CompiledFileSystemTest/TestFileSystem/foo/list&' |
| 89 'app_version=%s' % GetAppVersion(), |
| 86 factory.Create(f, CompiledFileSystemTest, category='foo')) | 90 factory.Create(f, CompiledFileSystemTest, category='foo')) |
| 87 | 91 |
| 88 def testPopulateFromFile(self): | 92 def testPopulateFromFile(self): |
| 89 def Sleepy(key, val): | 93 def Sleepy(key, val): |
| 90 return '%s%s' % ('Z' * len(key), 'z' * len(val)) | 94 return '%s%s' % ('Z' * len(key), 'z' * len(val)) |
| 91 compiled_fs = _CreateFactory().Create(Sleepy, CompiledFileSystemTest) | 95 compiled_fs = _CreateFactory().Create(Sleepy, CompiledFileSystemTest) |
| 92 self.assertEqual('ZZZZZZZZzzzzzzzzzzzzzzzzz', | 96 self.assertEqual('ZZZZZZZZzzzzzzzzzzzzzzzzz', |
| 93 compiled_fs.GetFromFile('404.html')) | 97 compiled_fs.GetFromFile('404.html')) |
| 94 self.assertEqual('ZZZZZZZZZZZZZZzzzzzzzzzzzzzzzzzz', | 98 self.assertEqual('ZZZZZZZZZZZZZZzzzzzzzzzzzzzzzzzz', |
| 95 compiled_fs.GetFromFile('apps/a11y.html')) | 99 compiled_fs.GetFromFile('apps/a11y.html')) |
| (...skipping 24 matching lines...) Expand all Loading... |
| 120 compiled_fs.GetFromFile('apps/') | 124 compiled_fs.GetFromFile('apps/') |
| 121 #self.assertRaises(SomeError, compiled_fs.GetFromFile, 'apps/') | 125 #self.assertRaises(SomeError, compiled_fs.GetFromFile, 'apps/') |
| 122 self.assertRaises(FileNotFoundError, | 126 self.assertRaises(FileNotFoundError, |
| 123 compiled_fs.GetFromFileListing, 'nodir/') | 127 compiled_fs.GetFromFileListing, 'nodir/') |
| 124 # TODO(kalman): likewise, not a FileNotFoundError. | 128 # TODO(kalman): likewise, not a FileNotFoundError. |
| 125 self.assertRaises(FileNotFoundError, | 129 self.assertRaises(FileNotFoundError, |
| 126 compiled_fs.GetFromFileListing, '404.html') | 130 compiled_fs.GetFromFileListing, '404.html') |
| 127 | 131 |
| 128 if __name__ == '__main__': | 132 if __name__ == '__main__': |
| 129 unittest.main() | 133 unittest.main() |
| OLD | NEW |