subversion_file_system_test.py revision c2e0dbddbe15c98d52c4786dac06cb8952a8ae6d
1#!/usr/bin/env python
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
4# found in the LICENSE file.
5
6import json
7import os
8import sys
9import unittest
10
11from fake_url_fetcher import FakeUrlFetcher
12from file_system import StatInfo
13from subversion_file_system import SubversionFileSystem
14
15class SubversionFileSystemTest(unittest.TestCase):
16  def setUp(self):
17    self._base_path = os.path.join(sys.path[0], 'test_data', 'file_system')
18    fetcher = FakeUrlFetcher(self._base_path)
19    self._file_system = SubversionFileSystem(fetcher, fetcher)
20
21  def _ReadLocalFile(self, filename):
22    with open(os.path.join(self._base_path, filename), 'r') as f:
23      return f.read()
24
25  def testReadFiles(self):
26    expected = {
27      'test1.txt': 'test1\n',
28      'test2.txt': 'test2\n',
29      'test3.txt': 'test3\n',
30    }
31    self.assertEqual(
32        expected,
33        self._file_system.Read(['test1.txt', 'test2.txt', 'test3.txt']).Get())
34
35  def testListDir(self):
36    expected = ['dir/']
37    for i in range(7):
38      expected.append('file%d.html' % i)
39    self.assertEqual(expected,
40                     sorted(self._file_system.ReadSingle('list/')))
41
42  def testDirStat(self):
43    stat_info = self._file_system.Stat('stat/')
44    expected = StatInfo(
45      '151113',
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)
53
54if __name__ == '__main__':
55  unittest.main()
56