| 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 json |
| 7 import os | 7 import os |
| 8 import sys | 8 import sys |
| 9 import unittest | 9 import unittest |
| 10 | 10 |
| 11 from fake_url_fetcher import FakeUrlFetcher | 11 from fake_url_fetcher import FakeUrlFetcher |
| 12 from file_system import StatInfo |
| 12 from subversion_file_system import SubversionFileSystem | 13 from subversion_file_system import SubversionFileSystem |
| 13 | 14 |
| 14 class SubversionFileSystemTest(unittest.TestCase): | 15 class SubversionFileSystemTest(unittest.TestCase): |
| 15 def setUp(self): | 16 def setUp(self): |
| 16 self._base_path = os.path.join(sys.path[0], 'test_data', 'file_system') | 17 self._base_path = os.path.join(sys.path[0], 'test_data', 'file_system') |
| 17 fetcher = FakeUrlFetcher(self._base_path) | 18 fetcher = FakeUrlFetcher(self._base_path) |
| 18 self._file_system = SubversionFileSystem(fetcher, fetcher) | 19 self._file_system = SubversionFileSystem(fetcher, fetcher) |
| 19 | 20 |
| 20 def _ReadLocalFile(self, filename): | 21 def _ReadLocalFile(self, filename): |
| 21 with open(os.path.join(self._base_path, filename), 'r') as f: | 22 with open(os.path.join(self._base_path, filename), 'r') as f: |
| 22 return f.read() | 23 return f.read() |
| 23 | 24 |
| 24 def testReadFiles(self): | 25 def testReadFiles(self): |
| 25 expected = { | 26 expected = { |
| 26 'test1.txt': 'test1\n', | 27 'test1.txt': 'test1\n', |
| 27 'test2.txt': 'test2\n', | 28 'test2.txt': 'test2\n', |
| 28 'test3.txt': 'test3\n', | 29 'test3.txt': 'test3\n', |
| 29 } | 30 } |
| 30 self.assertEqual( | 31 self.assertEqual( |
| 31 expected, | 32 expected, |
| 32 self._file_system.Read(['test1.txt', 'test2.txt', 'test3.txt']).Get()) | 33 self._file_system.Read(['test1.txt', 'test2.txt', 'test3.txt']).Get()) |
| 33 | 34 |
| 34 def testListDir(self): | 35 def testListDir(self): |
| 35 expected = ['dir/'] | 36 expected = ['dir/'] |
| 36 for i in range(7): | 37 for i in range(7): |
| 37 expected.append('file%d.html' % i) | 38 expected.append('file%d.html' % i) |
| 38 self.assertEqual(expected, | 39 self.assertEqual(expected, |
| 39 sorted(self._file_system.ReadSingle('list/'))) | 40 sorted(self._file_system.ReadSingle('list/'))) |
| 40 | 41 |
| 41 def testStat(self): | 42 def testDirStat(self): |
| 42 stat_info = self._file_system.Stat('stat/') | 43 stat_info = self._file_system.Stat('stat/') |
| 43 self.assertEquals('151113', stat_info.version) | 44 expected = StatInfo( |
| 44 self.assertEquals(json.loads(self._ReadLocalFile('stat_result.json')), | 45 '151113', |
| 45 stat_info.child_versions) | 46 child_versions=json.loads(self._ReadLocalFile('stat_result.json')) |
| 47 ) |
| 48 self.assertEquals(expected, stat_info) |
| 49 |
| 50 def testFileStat(self): |
| 51 stat_info = self._file_system.Stat('stat/extension_api.h') |
| 52 self.assertEquals(StatInfo('146163'), stat_info) |
| 46 | 53 |
| 47 if __name__ == '__main__': | 54 if __name__ == '__main__': |
| 48 unittest.main() | 55 unittest.main() |
| OLD | NEW |