| Index: chrome/common/extensions/docs/server2/test_file_system_test.py
|
| diff --git a/chrome/common/extensions/docs/server2/test_file_system_test.py b/chrome/common/extensions/docs/server2/test_file_system_test.py
|
| index e3b19a20d3161a1d69e7d86c192b03a70f799f81..eebf7f4fb0ad53171ed2898ab275c09a4399ea5d 100755
|
| --- a/chrome/common/extensions/docs/server2/test_file_system_test.py
|
| +++ b/chrome/common/extensions/docs/server2/test_file_system_test.py
|
| @@ -3,37 +3,37 @@
|
| # Use of this source code is governed by a BSD-style license that can be
|
| # found in the LICENSE file.
|
|
|
| +from copy import deepcopy
|
| from file_system import FileNotFoundError, StatInfo
|
| from test_file_system import TestFileSystem
|
| import unittest
|
|
|
| +_TEST_DATA = {
|
| + '404.html': '404.html contents',
|
| + 'apps': {
|
| + 'a11y.html': 'a11y.html contents',
|
| + 'about_apps.html': 'about_apps.html contents',
|
| + 'fakedir': {
|
| + 'file.html': 'file.html contents'
|
| + }
|
| + },
|
| + 'extensions': {
|
| + 'activeTab.html': 'activeTab.html contents',
|
| + 'alarms.html': 'alarms.html contents'
|
| + }
|
| +}
|
| +
|
| def _Get(fn):
|
| '''Returns a function which calls Future.Get on the result of |fn|.
|
| '''
|
| return lambda *args: fn(*args).Get()
|
|
|
| -def _CreateTestData():
|
| - return {
|
| - '404.html': '404.html contents',
|
| - 'apps': {
|
| - 'a11y.html': 'a11y.html contents',
|
| - 'about_apps.html': 'about_apps.html contents',
|
| - 'fakedir': {
|
| - 'file.html': 'file.html contents'
|
| - }
|
| - },
|
| - 'extensions': {
|
| - 'activeTab.html': 'activeTab.html contents',
|
| - 'alarms.html': 'alarms.html contents'
|
| - }
|
| - }
|
| -
|
| class TestFileSystemTest(unittest.TestCase):
|
| def testEmptyFileSystem(self):
|
| self._TestMetasyntacticPaths(TestFileSystem({}))
|
|
|
| def testNonemptyFileNotFoundErrors(self):
|
| - fs = TestFileSystem(_CreateTestData())
|
| + fs = TestFileSystem(deepcopy(_TEST_DATA))
|
| self._TestMetasyntacticPaths(fs)
|
| self.assertRaises(FileNotFoundError, _Get(fs.Read), ['404.html/'])
|
| self.assertRaises(FileNotFoundError, _Get(fs.Read), ['apps/foo/'])
|
| @@ -56,7 +56,7 @@ class TestFileSystemTest(unittest.TestCase):
|
| self.assertRaises(FileNotFoundError, fs.Stat, 'bar/baz')
|
|
|
| def testNonemptySuccess(self):
|
| - fs = TestFileSystem(_CreateTestData())
|
| + fs = TestFileSystem(deepcopy(_TEST_DATA))
|
| self.assertEqual('404.html contents', fs.ReadSingle('404.html'))
|
| self.assertEqual('404.html contents', fs.ReadSingle('/404.html'))
|
| self.assertEqual('a11y.html contents', fs.ReadSingle('apps/a11y.html'))
|
| @@ -68,7 +68,7 @@ class TestFileSystemTest(unittest.TestCase):
|
| set(fs.ReadSingle('/apps/')))
|
|
|
| def testStat(self):
|
| - fs = TestFileSystem(_CreateTestData())
|
| + fs = TestFileSystem(deepcopy(_TEST_DATA))
|
| self.assertRaises(FileNotFoundError, fs.Stat, 'foo')
|
| self.assertRaises(FileNotFoundError, fs.Stat, '404.html/')
|
| self.assertEquals(StatInfo('0'), fs.Stat('404.html'))
|
| @@ -76,6 +76,7 @@ class TestFileSystemTest(unittest.TestCase):
|
| 'activeTab.html': '0',
|
| 'alarms.html': '0',
|
| }), fs.Stat('extensions/'))
|
| +
|
| fs.IncrementStat()
|
| self.assertEquals(StatInfo('1'), fs.Stat('404.html'))
|
| self.assertEquals(StatInfo('1', child_versions={
|
| @@ -83,5 +84,79 @@ class TestFileSystemTest(unittest.TestCase):
|
| 'alarms.html': '1',
|
| }), fs.Stat('extensions/'))
|
|
|
| + fs.IncrementStat(path='404.html')
|
| + self.assertEquals(StatInfo('2'), fs.Stat('404.html'))
|
| + self.assertEquals(StatInfo('1', child_versions={
|
| + 'activeTab.html': '1',
|
| + 'alarms.html': '1',
|
| + }), fs.Stat('extensions/'))
|
| +
|
| + fs.IncrementStat()
|
| + self.assertEquals(StatInfo('3'), fs.Stat('404.html'))
|
| + self.assertEquals(StatInfo('2', child_versions={
|
| + 'activeTab.html': '2',
|
| + 'alarms.html': '2',
|
| + }), fs.Stat('extensions/'))
|
| +
|
| + fs.IncrementStat(path='extensions/')
|
| + self.assertEquals(StatInfo('3'), fs.Stat('404.html'))
|
| + self.assertEquals(StatInfo('3', child_versions={
|
| + 'activeTab.html': '2',
|
| + 'alarms.html': '2',
|
| + }), fs.Stat('extensions/'))
|
| +
|
| + fs.IncrementStat(path='extensions/alarms.html')
|
| + self.assertEquals(StatInfo('3'), fs.Stat('404.html'))
|
| + self.assertEquals(StatInfo('3', child_versions={
|
| + 'activeTab.html': '2',
|
| + 'alarms.html': '3',
|
| + }), fs.Stat('extensions/'))
|
| +
|
| + def testCheckAndReset(self):
|
| + fs = TestFileSystem(deepcopy(_TEST_DATA))
|
| +
|
| + self.assertTrue(fs.CheckAndReset())
|
| + self.assertFalse(fs.CheckAndReset(read_count=1))
|
| + self.assertFalse(fs.CheckAndReset(stat_count=1))
|
| +
|
| + fs.ReadSingle('apps/')
|
| + self.assertTrue(fs.CheckAndReset(read_count=1))
|
| + self.assertFalse(fs.CheckAndReset(read_count=1))
|
| + self.assertTrue(fs.CheckAndReset())
|
| +
|
| + fs.ReadSingle('apps/')
|
| + self.assertFalse(fs.CheckAndReset(read_count=2))
|
| +
|
| + fs.ReadSingle('extensions/')
|
| + fs.ReadSingle('extensions/')
|
| + self.assertTrue(fs.CheckAndReset(read_count=2))
|
| + self.assertFalse(fs.CheckAndReset(read_count=2))
|
| + self.assertTrue(fs.CheckAndReset())
|
| +
|
| + fs.ReadSingle('404.html')
|
| + fs.Read(['notfound.html', 'apps/'])
|
| + self.assertTrue(fs.CheckAndReset(read_count=2))
|
| +
|
| + fs.Stat('404.html')
|
| + fs.Stat('404.html')
|
| + fs.Stat('apps/')
|
| + self.assertFalse(fs.CheckAndReset(stat_count=42))
|
| + self.assertFalse(fs.CheckAndReset(stat_count=42))
|
| + self.assertTrue(fs.CheckAndReset())
|
| +
|
| + fs.ReadSingle('404.html')
|
| + fs.Stat('404.html')
|
| + fs.Stat('apps/')
|
| + self.assertTrue(fs.CheckAndReset(read_count=1, stat_count=2))
|
| + self.assertTrue(fs.CheckAndReset())
|
| +
|
| + def testMoveTo(self):
|
| + self.assertEqual({'foo': {'a': 'b', 'c': 'd'}},
|
| + TestFileSystem.MoveTo('foo', {'a': 'b', 'c': 'd'}))
|
| + self.assertEqual({'foo': {'bar': {'a': 'b', 'c': 'd'}}},
|
| + TestFileSystem.MoveTo('foo/bar', {'a': 'b', 'c': 'd'}))
|
| + self.assertEqual({'foo': {'bar': {'baz': {'a': 'b'}}}},
|
| + TestFileSystem.MoveTo('foo/bar/baz', {'a': 'b'}))
|
| +
|
| if __name__ == '__main__':
|
| unittest.main()
|
|
|