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.
7 from cStringIO
import StringIO
8 from zipfile
import ZipFile
10 from compiled_file_system
import CompiledFileSystem
11 from directory_zipper
import DirectoryZipper
12 from file_system
import FileNotFoundError
13 from test_file_system
import TestFileSystem
14 from object_store_creator
import ObjectStoreCreator
19 'one.txt': 'one.txt contents',
21 'three.txt': 'three.txt contents',
22 'four.txt': 'four.txt contents',
28 class DirectoryZipperTest(unittest
.TestCase
):
30 self
._directory
_zipper
= DirectoryZipper(
31 CompiledFileSystem
.Factory(ObjectStoreCreator
.ForTest()),
32 TestFileSystem(_TEST_DATA
))
35 top_zip
= ZipFile(StringIO(self
._directory
_zipper
.Zip('top/').Get()))
36 self
.assertEqual(['top/one.txt', 'top/two/four.txt', 'top/two/three.txt'],
37 sorted(top_zip
.namelist()))
38 self
.assertEqual('one.txt contents', top_zip
.read('top/one.txt'))
39 self
.assertEqual('three.txt contents', top_zip
.read('top/two/three.txt'))
40 self
.assertEqual('four.txt contents', top_zip
.read('top/two/four.txt'))
43 two_zip
= ZipFile(StringIO(self
._directory
_zipper
.Zip('top/two/').Get()))
44 self
.assertEqual(['two/four.txt', 'two/three.txt'],
45 sorted(two_zip
.namelist()))
46 self
.assertEqual('three.txt contents', two_zip
.read('two/three.txt'))
47 self
.assertEqual('four.txt contents', two_zip
.read('two/four.txt'))
49 def testNotFound(self
):
50 self
.assertRaises(FileNotFoundError
,
51 self
._directory
_zipper
.Zip('notfound/').Get
)
54 if __name__
== '__main__':