Exemple #1
0
 def test_path_unchanged(self):
     with utils.NamedTemporaryDirectory() as tmp_d:
         non_existing_path = tmp_d / 'does' / 'not' / 'exist'
         self.assertFalse(non_existing_path.exists())
         utils.is_writeable(non_existing_path)
         self.assertFalse(non_existing_path.exists())
         self.assertFalse((tmp_d / 'does').exists())
Exemple #2
0
    def test_make_dest_dir_w_oserror(self):
        with utils.NamedTemporaryDirectory() as tmp_d:
            test_file = os.path.join(tmp_d, 'test_file')
            open(test_file, 'w').close()

            with self.assertRaisesRegexp(OSError, 'File exists'):
                utils.make_dest_dir(test_file)
            self.assertFalse(os.path.isdir(test_file))
Exemple #3
0
    def test_w_error_chdir(self):
        tmp_d = None
        with self.assertRaises(ValueError):
            with utils.NamedTemporaryDirectory(change_dir=True) as tmp_d:
                self.assertTrue(tmp_d.exists())
                raise ValueError()

        self.assertFalse(tmp_d.exists())
Exemple #4
0
    def test_w_chdir(self):
        tmp_d = None
        with utils.NamedTemporaryDirectory(change_dir=True) as tmp_d:
            self.assertTrue(tmp_d.exists())
            p = Path('.').expand().abspath()
            self.assertTrue(tmp_d in p)

        self.assertFalse(tmp_d.exists())
Exemple #5
0
 def test_make_dest_dir_w_enotdir_error(self):
     with utils.NamedTemporaryDirectory() as tmp_d:
         test_file = os.path.join(tmp_d, 'test_file')
         open(test_file, 'w').close()
         with self.assertRaisesRegexp(OSError,
                                      'already exists as a file') as exc:
             new_dir = os.path.join(test_file, 'test')
             utils.make_dest_dir(new_dir)
         self.assertEquals(exc.exception.errno, errno.ENOTDIR)
         self.assertFalse(os.path.isdir(new_dir))
Exemple #6
0
 def test_w_dir(self):
     # Create an empty directory for this test in ./swift_upload. This
     # is because git doesnt allow a truly empty directory to be checked
     # in
     with utils.NamedTemporaryDirectory(dir=self.swift_dir) as tmp_dir:
         uploads = utils.walk_files_and_dirs([self.swift_dir])
         self.assertEquals(
             set(uploads),
             set([
                 self.swift_dir / 'file1',
                 tmp_dir,
                 self.swift_dir / 'data_dir' / 'file2',
             ]))
Exemple #7
0
 def test_w_broken_symlink(self):
     swift_dir = (Path(__file__).expand().abspath().parent / 'swift_upload')
     with utils.NamedTemporaryDirectory(dir=swift_dir) as tmp_dir:
         symlink = tmp_dir / 'broken.symlink'
         symlink_source = tmp_dir / 'nonexistent'
         # put something in symlink source so that Python doesn't complain
         with stor.open(symlink_source, 'w') as fp:
             fp.write('blah')
         os.symlink(symlink_source, symlink)
         uploads = utils.walk_files_and_dirs([swift_dir])
         self.assertEquals(
             set(uploads),
             set([
                 swift_dir / 'file1',
                 swift_dir / 'data_dir' / 'file2',
                 symlink,
                 symlink_source,
             ]))
         # NOW: destroy it with fire and we have empty directory
         os.remove(symlink_source)
         uploads = utils.walk_files_and_dirs([swift_dir])
         self.assertEquals(
             set(uploads),
             set([
                 swift_dir / 'file1',
                 tmp_dir,
                 swift_dir / 'data_dir' / 'file2',
             ]))
         # but put a sub directory, now tmp_dir doesn't show up
         subdir = tmp_dir / 'subdir'
         subdir.makedirs_p()
         uploads = utils.walk_files_and_dirs([swift_dir])
         self.assertEquals(
             set(uploads),
             set([
                 swift_dir / 'file1',
                 subdir,
                 swift_dir / 'data_dir' / 'file2',
             ]))
Exemple #8
0
 def test_path_no_perms(self):
     with utils.NamedTemporaryDirectory() as tmp_d:
         os.chmod(tmp_d, stat.S_IREAD | stat.S_IRGRP | stat.S_IROTH)
         self.assertFalse(utils.is_writeable(tmp_d))
Exemple #9
0
 def test_existing_path_not_removed(self):
     with utils.NamedTemporaryDirectory() as tmp_d:
         self.assertTrue(tmp_d.exists())
         utils.is_writeable(tmp_d)
         self.assertTrue(tmp_d.exists())
Exemple #10
0
 def test_non_existing_path(self):
     with utils.NamedTemporaryDirectory() as tmp_d:
         non_existing_path = tmp_d / 'does' / 'not' / 'exist'
         self.assertFalse(utils.is_writeable(non_existing_path))
Exemple #11
0
 def test_existing_path(self):
     with utils.NamedTemporaryDirectory() as tmp_d:
         self.assertTrue(utils.is_writeable(tmp_d))
Exemple #12
0
 def test_make_dest_dir_existing(self):
     with utils.NamedTemporaryDirectory() as tmp_d:
         dest_dir = os.path.join(tmp_d, 'test')
         os.mkdir(dest_dir)
         utils.make_dest_dir(dest_dir)
         self.assertTrue(os.path.isdir(dest_dir))
Exemple #13
0
    def test_wo_chdir(self):
        tmp_d = None
        with utils.NamedTemporaryDirectory() as tmp_d:
            self.assertTrue(tmp_d.exists())

        self.assertFalse(tmp_d.exists())