OLD | NEW |
(Empty) | |
| 1 #!/usr/bin/env python |
| 2 # Copyright 2013 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 |
| 6 from copy import deepcopy |
| 7 from file_system import FileNotFoundError, StatInfo |
| 8 from mock_file_system import MockFileSystem |
| 9 from test_file_system import TestFileSystem |
| 10 import unittest |
| 11 |
| 12 _TEST_DATA = { |
| 13 '404.html': '404.html contents', |
| 14 'apps': { |
| 15 'a11y.html': 'a11y.html contents', |
| 16 'about_apps.html': 'about_apps.html contents', |
| 17 'fakedir': { |
| 18 'file.html': 'file.html contents' |
| 19 } |
| 20 }, |
| 21 'extensions': { |
| 22 'activeTab.html': 'activeTab.html contents', |
| 23 'alarms.html': 'alarms.html contents' |
| 24 } |
| 25 } |
| 26 |
| 27 def _Get(fn): |
| 28 '''Returns a function which calls Future.Get on the result of |fn|. |
| 29 ''' |
| 30 return lambda *args: fn(*args).Get() |
| 31 |
| 32 class MockFileSystemTest(unittest.TestCase): |
| 33 def testCheckAndReset(self): |
| 34 fs = MockFileSystem(TestFileSystem(deepcopy(_TEST_DATA))) |
| 35 |
| 36 self.assertTrue(*fs.CheckAndReset()) |
| 37 self.assertFalse(*fs.CheckAndReset(read_count=1)) |
| 38 self.assertFalse(*fs.CheckAndReset(stat_count=1)) |
| 39 |
| 40 fs.ReadSingle('apps/') |
| 41 self.assertTrue(*fs.CheckAndReset(read_count=1)) |
| 42 self.assertFalse(*fs.CheckAndReset(read_count=1)) |
| 43 self.assertTrue(*fs.CheckAndReset()) |
| 44 |
| 45 fs.ReadSingle('apps/') |
| 46 self.assertFalse(*fs.CheckAndReset(read_count=2)) |
| 47 |
| 48 fs.ReadSingle('extensions/') |
| 49 fs.ReadSingle('extensions/') |
| 50 self.assertTrue(*fs.CheckAndReset(read_count=2)) |
| 51 self.assertFalse(*fs.CheckAndReset(read_count=2)) |
| 52 self.assertTrue(*fs.CheckAndReset()) |
| 53 |
| 54 fs.ReadSingle('404.html') |
| 55 fs.Read(['notfound.html', 'apps/']) |
| 56 self.assertTrue(*fs.CheckAndReset(read_count=2)) |
| 57 |
| 58 fs.Stat('404.html') |
| 59 fs.Stat('404.html') |
| 60 fs.Stat('apps/') |
| 61 self.assertFalse(*fs.CheckAndReset(stat_count=42)) |
| 62 self.assertFalse(*fs.CheckAndReset(stat_count=42)) |
| 63 self.assertTrue(*fs.CheckAndReset()) |
| 64 |
| 65 fs.ReadSingle('404.html') |
| 66 fs.Stat('404.html') |
| 67 fs.Stat('apps/') |
| 68 self.assertTrue(*fs.CheckAndReset(read_count=1, stat_count=2)) |
| 69 self.assertTrue(*fs.CheckAndReset()) |
| 70 |
| 71 if __name__ == '__main__': |
| 72 unittest.main() |
OLD | NEW |