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