Home | History | Annotate | Download | only in system
      1 # Copyright (C) 2010 Google Inc. All rights reserved.
      2 #
      3 # Redistribution and use in source and binary forms, with or without
      4 # modification, are permitted provided that the following conditions
      5 # are met:
      6 #
      7 # 1.  Redistributions of source code must retain the above copyright
      8 #     notice, this list of conditions and the following disclaimer.
      9 # 2.  Redistributions in binary form must reproduce the above copyright
     10 #     notice, this list of conditions and the following disclaimer in the
     11 #     documentation and/or other materials provided with the distribution.
     12 #
     13 # THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
     14 # EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
     15 # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
     16 # DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
     17 # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
     18 # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
     19 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
     20 # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     21 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     22 # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     23 
     24 from __future__ import with_statement
     25 
     26 import unittest
     27 
     28 from webkitpy.common.system.directoryfileset import DirectoryFileSet
     29 from webkitpy.common.system.filesystem_mock import MockFileSystem
     30 
     31 
     32 class DirectoryFileSetTest(unittest.TestCase):
     33     def setUp(self):
     34         files = {}
     35         files['/test/some-file'] = 'contents'
     36         files['/test/some-other-file'] = 'other contents'
     37         files['/test/b/c'] = 'c'
     38         self._filesystem = MockFileSystem(files)
     39         self._fileset = DirectoryFileSet('/test', self._filesystem)
     40 
     41     def test_files_in_namelist(self):
     42         self.assertTrue('some-file' in self._fileset.namelist())
     43         self.assertTrue('some-other-file' in self._fileset.namelist())
     44         self.assertTrue('b/c' in self._fileset.namelist())
     45 
     46     def test_read(self):
     47         self.assertEquals('contents', self._fileset.read('some-file'))
     48 
     49     def test_open(self):
     50         file = self._fileset.open('some-file')
     51         self.assertEquals('some-file', file.name())
     52         self.assertEquals('contents', file.contents())
     53 
     54     def test_extract(self):
     55         self._fileset.extract('some-file', '/test-directory')
     56         contents = self._filesystem.read_text_file('/test-directory/some-file')
     57         self.assertEquals('contents', contents)
     58 
     59     def test_extract_deep_file(self):
     60         self._fileset.extract('b/c', '/test-directory')
     61         self.assertTrue(self._filesystem.exists('/test-directory/b/c'))
     62 
     63     def test_delete(self):
     64         self.assertTrue(self._filesystem.exists('/test/some-file'))
     65         self._fileset.delete('some-file')
     66         self.assertFalse(self._filesystem.exists('/test/some-file'))
     67 
     68 
     69 if __name__ == '__main__':
     70     unittest.main()
     71