Пример #1
0
 def test_stat_file_in_unreadable_dir(self):
     self.check_posix_only()
     dir_path = self.make_path('some_dir')
     file_path = self.os.path.join(dir_path, 'some_file')
     self.create_file(file_path)
     self.os.chmod(dir_path, 0o000)
     if not is_root():
         self.assert_raises_os_error(errno.EACCES,
                                     self.path(file_path).stat)
     else:
         self.assertEqual(0, self.path(file_path).stat().st_size)
Пример #2
0
 def test_iterdir_in_unreadable_dir(self):
     self.check_posix_only()
     dir_path = self.make_path('some_dir')
     file_path = self.os.path.join(dir_path, 'some_file')
     self.create_file(file_path)
     self.os.chmod(dir_path, 0o000)
     iter = self.path(dir_path).iterdir()
     if not is_root():
         self.assert_raises_os_error(errno.EACCES, list, iter)
     else:
         path = str(list(iter)[0])
         self.assertTrue(path.endswith('some_file'))
 def test_rmtree_without_permission_for_a_dir_in_posix(self):
     self.check_posix_only()
     dir_path = self.make_path('foo')
     self.create_file(os.path.join(dir_path, 'bar'))
     file_path = os.path.join(dir_path, 'baz')
     self.create_file(file_path)
     self.os.chmod(dir_path, 0o555)
     if not is_root():
         self.assertRaises(OSError, shutil.rmtree, dir_path)
         self.assertTrue(os.path.exists(file_path))
         self.os.chmod(dir_path, 0o777)
     else:
         shutil.rmtree(dir_path)
         self.assertFalse(os.path.exists(file_path))
 def test_raises_if_src_not_readable(self):
     self.check_posix_only()
     src_file = self.make_path('xyzzy')
     dst_file = self.make_path('xyzzy_copy')
     src_contents = 'contents of source file'
     self.create_file(src_file, contents=src_contents)
     os.chmod(src_file, 0o000)
     self.assertTrue(os.path.exists(src_file))
     if not is_root():
         self.assertRaises(IOError, shutil.copyfile, src_file, dst_file)
     else:
         shutil.copyfile(src_file, dst_file)
         self.assertTrue(os.path.exists(dst_file))
         self.check_contents(dst_file, src_contents)
 def test_raises_if_dest_dir_is_not_writable_under_posix(self):
     self.check_posix_only()
     src_file = self.make_path('xyzzy')
     dst_dir = self.make_path('tmp', 'foo')
     dst_file = os.path.join(dst_dir, 'xyzzy')
     src_contents = 'contents of source file'
     self.create_file(src_file, contents=src_contents)
     self.create_dir(dst_dir)
     os.chmod(dst_dir, 0o555)
     self.assertTrue(os.path.exists(src_file))
     self.assertTrue(os.path.exists(dst_dir))
     if not is_root():
         self.assertRaises(OSError, shutil.copyfile, src_file, dst_file)
     else:
         shutil.copyfile(src_file, dst_file)
         self.assertTrue(os.path.exists(dst_file))
         self.check_contents(dst_file, src_contents)
    def test_raises_if_dest_exists_and_is_not_writable(self):
        src_file = self.make_path('xyzzy')
        dst_file = self.make_path('xyzzy_copy')
        src_contents = 'contents of source file'
        dst_contents = 'contents of dest file'
        self.create_file(src_file, contents=src_contents)
        self.create_file(dst_file, contents=dst_contents)
        os.chmod(dst_file, 0o400)
        self.assertTrue(os.path.exists(src_file))
        self.assertTrue(os.path.exists(dst_file))

        if is_root():
            shutil.copyfile(src_file, dst_file)
            self.assertTrue(self.os.path.exists(dst_file))
            with self.open(dst_file) as f:
                self.assertEqual('contents of source file', f.read())
        else:
            self.assertRaises(IOError, shutil.copyfile, src_file, dst_file)

        os.chmod(dst_file, 0o666)