Beispiel #1
0
 def setUp(self):
     self.fstree = FSTree()
Beispiel #2
0
class TestFSTree(unittest.TestCase):
    def setUp(self):
        self.fstree = FSTree()

    def test_add_single_file(self):
        '''Check that the FSTree updates correctly when a single file is added.
        '''
        with mocked_stat():
            self.fstree.add_path('foo', sentinel.file_stat, False)
            self.assertEqual([('foo', sentinel.file_stat, False, [])],
                             store_to_list(self.fstree.store))

    def test_add_two_files(self):
        '''Check that the FSTree updates correctly when two files are added.

        The FSTree should sort the files lexicographically by name.
        '''
        with mocked_stat():
            self.fstree.add_path('foo', sentinel.file_stat, False)
            self.fstree.add_path('bar', sentinel.file_stat, False)
            self.assertEqual([('bar', sentinel.file_stat, False, []),
                              ('foo', sentinel.file_stat, False, [])],
                             store_to_list(self.fstree.store))

    def test_add_dir_with_file(self):
        '''Check that FSTree updates correctly with a dir containing a file.

        The file should be placed inside the directory.
        '''
        with mocked_stat():
            self.fstree.add_path('dir', sentinel.dir_stat)
            self.fstree.add_path('dir/file', sentinel.file_stat, False)
            self.assertEqual([('dir', sentinel.dir_stat, True, [
                ('dir/file', sentinel.file_stat, False, []),
            ])], store_to_list(self.fstree.store))

    def test_add_dir_with_files(self):
        '''Check that two files within a directory are handled properly.

        The files should be sorted lexicographically by name.
        '''
        with mocked_stat():
            self.fstree.add_path('dir', sentinel.dir_stat)
            self.fstree.add_path('dir/foo', sentinel.file_stat, False)
            self.fstree.add_path('dir/bar', sentinel.file_stat, False)
            self.assertEqual([('dir', sentinel.dir_stat, True, [
                ('dir/bar', sentinel.file_stat, False, []),
                ('dir/foo', sentinel.file_stat, False, [])
            ])], store_to_list(self.fstree.store))