| OLD | NEW |
| (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 unittest | |
| 7 | |
| 8 from caching_file_system import CachingFileSystem | |
| 9 from file_system import FileNotFoundError | |
| 10 from host_file_system_creator import HostFileSystemCreator | |
| 11 from object_store_creator import ObjectStoreCreator | |
| 12 from offline_file_system import OfflineFileSystem | |
| 13 from test_data.canned_data import CANNED_API_FILE_SYSTEM_DATA | |
| 14 from test_file_system import TestFileSystem | |
| 15 | |
| 16 def ConstructorForTest(branch, revision=None): | |
| 17 return TestFileSystem(CANNED_API_FILE_SYSTEM_DATA[str(branch)]) | |
| 18 | |
| 19 class HostFileSystemCreatorTest(unittest.TestCase): | |
| 20 def setUp(self): | |
| 21 self._idle_path = 'api/idle.json' | |
| 22 | |
| 23 def testWithCaching(self): | |
| 24 creator = HostFileSystemCreator(ObjectStoreCreator.ForTest(), | |
| 25 constructor_for_test=ConstructorForTest) | |
| 26 | |
| 27 fs = creator.Create('trunk') | |
| 28 firstRead = fs.ReadSingle(self._idle_path) | |
| 29 CANNED_API_FILE_SYSTEM_DATA['trunk']['api']['idle.json'] = 'blah blah blah' | |
| 30 secondRead = fs.ReadSingle(self._idle_path) | |
| 31 | |
| 32 self.assertEqual(firstRead, secondRead) | |
| 33 | |
| 34 def testWithOffline(self): | |
| 35 creator = HostFileSystemCreator(ObjectStoreCreator.ForTest(), | |
| 36 offline=True, | |
| 37 constructor_for_test=ConstructorForTest) | |
| 38 | |
| 39 fs = creator.Create('trunk') | |
| 40 # Offline file system should raise a FileNotFoundError if read is attempted. | |
| 41 self.assertRaises(FileNotFoundError, fs.ReadSingle, self._idle_path) | |
| 42 | |
| 43 if __name__ == '__main__': | |
| 44 unittest.main() | |
| OLD | NEW |