| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright 2014 The Chromium Authors. All rights reserved. | 2 # Copyright 2014 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 base64 | 6 import base64 |
| 7 import json | 7 import json |
| 8 import unittest | 8 import unittest |
| 9 | 9 |
| 10 from extensions_paths import SERVER2 | 10 from extensions_paths import SERVER2 |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 'public_extensions')) | 58 'public_extensions')) |
| 59 # ALWAYS skip not found here. | 59 # ALWAYS skip not found here. |
| 60 content = self._fs.Read((path,), | 60 content = self._fs.Read((path,), |
| 61 skip_not_found=True).Get().get(path, None) | 61 skip_not_found=True).Get().get(path, None) |
| 62 if content is None: | 62 if content is None: |
| 63 # GitilesFS expects a DownloadError if the file wasn't found. | 63 # GitilesFS expects a DownloadError if the file wasn't found. |
| 64 raise DownloadError | 64 raise DownloadError |
| 65 # GitilesFS expects directory content as a JSON string. | 65 # GitilesFS expects directory content as a JSON string. |
| 66 if 'JSON' in fmt: | 66 if 'JSON' in fmt: |
| 67 content = json.dumps({ | 67 content = json.dumps({ |
| 68 'entries': [{'name': name} for name in content] | 68 'entries': [ |
| 69 { |
| 70 # GitilesFS expects directory names to not have a trailing '/'. |
| 71 'name': name.rstrip('/'), |
| 72 'type': 'tree' if name.endswith('/') else 'blob' |
| 73 } for name in content] |
| 69 }) | 74 }) |
| 70 return _Response(content) | 75 return _Response(content) |
| 71 return Future(callback=resolve) | 76 return Future(callback=resolve) |
| 72 | 77 |
| 73 | 78 |
| 74 class GitilesFileSystemTest(unittest.TestCase): | 79 class GitilesFileSystemTest(unittest.TestCase): |
| 75 def setUp(self): | 80 def setUp(self): |
| 76 fetcher = _FakeGitilesFetcher(TestFileSystem(_TEST_FS)) | 81 fetcher = _FakeGitilesFetcher(TestFileSystem(_TEST_FS)) |
| 77 self._gitiles_fs = GitilesFileSystem(fetcher, _BASE_URL, '', '') | 82 self._gitiles_fs = GitilesFileSystem(fetcher, _BASE_URL, '', '') |
| 78 | 83 |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 140 def testGetCommitID(self): | 145 def testGetCommitID(self): |
| 141 self.assertEqual(self._gitiles_fs.GetCommitID().Get(), 'a_commit') | 146 self.assertEqual(self._gitiles_fs.GetCommitID().Get(), 'a_commit') |
| 142 | 147 |
| 143 def testStat(self): | 148 def testStat(self): |
| 144 self.assertEqual(self._gitiles_fs.Stat(_REAL_DATA_DIR).version, | 149 self.assertEqual(self._gitiles_fs.Stat(_REAL_DATA_DIR).version, |
| 145 'ec21e736a3f00db2c0580e3cf71d91951656caec') | 150 'ec21e736a3f00db2c0580e3cf71d91951656caec') |
| 146 | 151 |
| 147 | 152 |
| 148 if __name__ == '__main__': | 153 if __name__ == '__main__': |
| 149 unittest.main() | 154 unittest.main() |
| OLD | NEW |