Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 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 json | |
| 6 import os | 7 import os |
| 7 import unittest | 8 import unittest |
| 8 | 9 |
| 9 from fake_url_fetcher import FakeUrlFetcher | 10 from appengine_blobstore import AppEngineBlobstore |
| 11 from appengine_url_fetcher import AppEngineUrlFetcher | |
| 12 from fake_fetchers import ConfigureFakeFetchers | |
| 10 from github_file_system import GithubFileSystem | 13 from github_file_system import GithubFileSystem |
| 11 from in_memory_object_store import InMemoryObjectStore | 14 from in_memory_object_store import InMemoryObjectStore |
| 12 | 15 import url_constants |
| 13 class FakeBlobstore(object): | |
| 14 def Set(self, blob, key, version): | |
| 15 return None | |
| 16 | |
| 17 def Get(self, key, version): | |
| 18 return None | |
| 19 | |
| 20 def Delete(self, key, version): | |
| 21 return None | |
| 22 | |
| 23 class FakeGithubFetcher(FakeUrlFetcher): | |
| 24 class _Response(object): | |
| 25 def __init__(self, content): | |
| 26 self.content = content | |
| 27 | |
| 28 def Fetch(self, path): | |
| 29 if path == 'zipball': | |
| 30 return super(FakeGithubFetcher, self).Fetch('file_system.zip') | |
| 31 return self._Response('{ "commit": { "tree": { "sha": 0 } } }') | |
| 32 | 16 |
| 33 class GithubFileSystemTest(unittest.TestCase): | 17 class GithubFileSystemTest(unittest.TestCase): |
| 34 def setUp(self): | 18 def setUp(self): |
| 35 self._file_system = GithubFileSystem(FakeGithubFetcher('test_data'), | 19 ConfigureFakeFetchers() |
| 36 InMemoryObjectStore('test'), | 20 self._base_path = os.path.join('test_data', 'github_file_system') |
| 37 FakeBlobstore()) | 21 self._file_system = GithubFileSystem( |
| 22 AppEngineUrlFetcher(url_constants.GITHUB_URL), | |
| 23 InMemoryObjectStore('github'), | |
| 24 AppEngineBlobstore()) | |
| 38 | 25 |
| 39 def testReadFiles(self): | 26 def _ReadLocalFile(self, filename): |
| 40 expected = { | 27 with open(os.path.join(self._base_path, filename), 'r') as f: |
| 41 '/test1.txt': 'test1\n', | 28 return f.read() |
| 42 '/test2.txt': 'test2\n', | |
| 43 '/test3.txt': 'test3\n', | |
| 44 } | |
| 45 self.assertEqual( | |
| 46 expected, | |
| 47 self._file_system.Read( | |
| 48 ['/test1.txt', '/test2.txt', '/test3.txt']).Get()) | |
| 49 | 29 |
| 50 def testListDir(self): | 30 def testList(self): |
| 51 expected = ['dir/'] | 31 self.assertEqual(json.loads(self._ReadLocalFile('expected_list.json')), |
| 52 for i in range(7): | 32 self._file_system.Read(['/']).Get()) |
| 53 expected.append('file%d.html' % i) | 33 |
| 54 self.assertEqual(expected, | 34 def testRead(self): |
| 55 sorted(self._file_system.ReadSingle('/list/'))) | 35 self.assertEqual(self._ReadLocalFile('expected_read.txt'), |
| 36 self._file_system.ReadSingle('/analytics/launch.js')) | |
| 37 | |
| 38 def testStat(self): | |
| 39 self.assertEqual(0, self._file_system.Stat('zipball').version) | |
|
not at google - send to devlin
2012/08/22 13:57:58
and these tests picked up the bug?
cduvall
2012/08/22 17:20:43
Yeah these tests caught the error, but I just adde
| |
| 56 | 40 |
| 57 if __name__ == '__main__': | 41 if __name__ == '__main__': |
| 58 unittest.main() | 42 unittest.main() |
| OLD | NEW |