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.
8 from chained_compiled_file_system
import ChainedCompiledFileSystem
9 from compiled_file_system
import CompiledFileSystem
10 from object_store_creator
import ObjectStoreCreator
11 from test_file_system
import TestFileSystem
14 'a.txt': 'base a.txt',
22 'new.txt': 'a new file',
25 'new.txt': 'new file in dir',
29 identity
= lambda _
, x
: x
31 class ChainedCompiledFileSystemTest(unittest
.TestCase
):
33 object_store_creator
= ObjectStoreCreator(start_empty
=False)
34 base_file_system
= TestFileSystem(_TEST_DATA_BASE
, identity
='base')
35 self
._base
_compiled
_fs
= CompiledFileSystem
.Factory(
36 object_store_creator
).Create(base_file_system
,
38 ChainedCompiledFileSystemTest
)
39 chained_factory
= ChainedCompiledFileSystem
.Factory([base_file_system
],
41 self
._new
_file
_system
= TestFileSystem(_TEST_DATA_NEW
, identity
='new')
42 self
._chained
_compiled
_fs
= chained_factory
.Create(
43 self
._new
_file
_system
, identity
, ChainedCompiledFileSystemTest
)
45 def testGetFromFile(self
):
46 self
.assertEqual(self
._chained
_compiled
_fs
.GetFromFile('a.txt').Get(),
47 self
._base
_compiled
_fs
.GetFromFile('a.txt').Get())
48 self
.assertEqual(self
._chained
_compiled
_fs
.GetFromFile('new.txt').Get(),
50 self
.assertEqual(self
._chained
_compiled
_fs
.GetFromFile('dir/new.txt').Get(),
52 self
._new
_file
_system
.IncrementStat('a.txt')
53 self
.assertNotEqual(self
._chained
_compiled
_fs
.GetFromFile('a.txt').Get(),
54 self
._base
_compiled
_fs
.GetFromFile('a.txt').Get())
55 self
.assertEqual(self
._chained
_compiled
_fs
.GetFromFile('a.txt').Get(),
56 self
._new
_file
_system
.ReadSingle('a.txt').Get())
58 def testGetFromFileListing(self
):
59 self
.assertEqual(self
._chained
_compiled
_fs
.GetFromFileListing('dir/').Get(),
60 self
._base
_compiled
_fs
.GetFromFileListing('dir/').Get())
61 self
._new
_file
_system
.IncrementStat('dir/new.txt')
63 self
._chained
_compiled
_fs
.GetFromFileListing('dir/').Get(),
64 self
._base
_compiled
_fs
.GetFromFileListing('dir/').Get())
66 self
._chained
_compiled
_fs
.GetFromFileListing('dir/').Get(),
67 self
._new
_file
_system
.ReadSingle('dir/').Get())
69 if __name__
== '__main__':