예제 #1
0
 def test_create(self):
     with temp_dir(False) as d:
         file_archive.FileStore.create_store(d)
         self.assertTrue(os.path.isdir(d))
         self.assertTrue(os.path.isfile(os.path.join(d, 'database')))
     with temp_dir(True) as d:
         file_archive.FileStore.create_store(d)
         self.assertTrue(os.path.isfile(os.path.join(d, 'database')))
예제 #2
0
 def test_create(self):
     with temp_dir(False) as d:
         file_archive.FileStore.create_store(d)
         self.assertTrue(os.path.isdir(d))
         self.assertTrue(os.path.isfile(os.path.join(d, 'database')))
     with temp_dir(True) as d:
         file_archive.FileStore.create_store(d)
         self.assertTrue(os.path.isfile(os.path.join(d, 'database')))
예제 #3
0
 def test_create_nonempty(self):
     with temp_dir() as d:
         with open(os.path.join(d, 'somefile'), 'wb') as fp:
             fp.write(b"I'm not empty\n")
         with self.assertRaises(file_archive.CreationError):
             file_archive.FileStore.create_store(d)
     with temp_dir() as d:
         file_archive.FileStore.create_store(d)
         with self.assertRaises(file_archive.CreationError):
             file_archive.FileStore.create_store(d)
예제 #4
0
 def test_create_nonempty(self):
     with temp_dir() as d:
         with open(os.path.join(d, 'somefile'), 'wb') as fp:
             fp.write(b"I'm not empty\n")
         with self.assertRaises(file_archive.CreationError):
             file_archive.FileStore.create_store(d)
     with temp_dir() as d:
         file_archive.FileStore.create_store(d)
         with self.assertRaises(file_archive.CreationError):
             file_archive.FileStore.create_store(d)
예제 #5
0
 def test_open_invalid(self):
     with temp_dir() as d:
         with self.assertRaises(file_archive.InvalidStore):
             file_archive.FileStore(d)
     with temp_dir() as d:
         os.mkdir(os.path.join(d, 'objects'))
         with self.assertRaises(file_archive.InvalidStore):
             file_archive.FileStore(d)
     with temp_dir() as d:
         with open(os.path.join(d, 'database'), 'wb'):
             pass
         with self.assertRaises(file_archive.InvalidStore):
             file_archive.FileStore(d)
예제 #6
0
 def test_open_invalid(self):
     with temp_dir() as d:
         with self.assertRaises(file_archive.InvalidStore):
             file_archive.FileStore(d)
     with temp_dir() as d:
         os.mkdir(os.path.join(d, 'objects'))
         with self.assertRaises(file_archive.InvalidStore):
             file_archive.FileStore(d)
     with temp_dir() as d:
         with open(os.path.join(d, 'database'), 'wb'):
             pass
         with self.assertRaises(file_archive.InvalidStore):
             file_archive.FileStore(d)
예제 #7
0
    def test_relativize_link(self):
        with temp_dir() as t:
            relativize_link = file_archive.relativize_link
            join = os.path.join

            d = join(t, 'inner')
            os.mkdir(d)
            i = join(d, 'dirI')
            os.mkdir(i)
            j = join(d, 'dirJ')
            os.mkdir(j)
            os.symlink(join(d, 'file'), join(i, 'link1'))
            os.symlink('../file', join(i, 'link1r'))
            os.symlink(join(j, 'file'), join(i, 'link2'))
            os.symlink('../dirJ/file', join(i, 'link2r'))
            os.symlink(join(j, 'file'), join(d, 'link3'))
            os.symlink('dirJ/file', join(d, 'link3r'))
            os.symlink(join(t, 'file'), join(i, 'link4'))
            os.symlink('../../file', join(i, 'link4r'))
            os.symlink(join(t, 'file'), join(d, 'link5'))
            os.symlink('../file', join(d, 'link5r'))

            self.assertEqual(relativize_link(join(i, 'link1'), d), '../file')
            self.assertEqual(relativize_link(join(i, 'link2'), d),
                             '../dirJ/file')
            self.assertEqual(relativize_link(join(d, 'link3'), d), 'dirJ/file')
            self.assertEqual(relativize_link(join(i, 'link4'), d), None)
            self.assertEqual(relativize_link(join(d, 'link5'), d), None)
예제 #8
0
    def test_relativize_link(self):
        with temp_dir() as t:
            relativize_link = file_archive.relativize_link
            join = os.path.join

            d = join(t, 'inner')
            os.mkdir(d)
            i = join(d, 'dirI')
            os.mkdir(i)
            j = join(d, 'dirJ')
            os.mkdir(j)
            os.symlink(join(d, 'file'), join(i, 'link1'))
            os.symlink('../file', join(i, 'link1r'))
            os.symlink(join(j, 'file'), join(i, 'link2'))
            os.symlink('../dirJ/file', join(i, 'link2r'))
            os.symlink(join(j, 'file'), join(d, 'link3'))
            os.symlink('dirJ/file', join(d, 'link3r'))
            os.symlink(join(t, 'file'), join(i, 'link4'))
            os.symlink('../../file', join(i, 'link4r'))
            os.symlink(join(t, 'file'), join(d, 'link5'))
            os.symlink('../file', join(d, 'link5r'))

            self.assertEqual(relativize_link(join(i, 'link1'), d),
                             '../file')
            self.assertEqual(relativize_link(join(i, 'link2'), d),
                             '../dirJ/file')
            self.assertEqual(relativize_link(join(d, 'link3'), d),
                             'dirJ/file')
            self.assertEqual(relativize_link(join(i, 'link4'), d),
                             None)
            self.assertEqual(relativize_link(join(d, 'link5'), d),
                             None)
예제 #9
0
 def test_symlink_recursive(self):
     with temp_dir() as d:
         shutil.copyfile(self.t('file1.bin'), os.path.join(d, 'file'))
         os.symlink(d, os.path.join(d, 'link'))
         with temp_warning_filter():
             warnings.filterwarnings(
                 'ignore',
                 '.*is a symbolic link, recursing on target directory$',
                 file_archive.UsageWarning)
             with self.assertRaises(ValueError):
                 self.store.add_directory(d, {'some': 'data'})
예제 #10
0
 def test_symlink_recursive(self):
     with temp_dir() as d:
         shutil.copyfile(self.t('file1.bin'), os.path.join(d, 'file'))
         os.symlink(d, os.path.join(d, 'link'))
         with temp_warning_filter():
             warnings.filterwarnings(
                 'ignore',
                 '.*is a symbolic link, recursing on target directory$',
                 file_archive.UsageWarning)
             with self.assertRaises(ValueError):
                 self.store.add_directory(d, {'some': 'data'})
예제 #11
0
 def test_external_symlink(self):
     def test_warning(warns):
         self.assertEqual(len(warns), 1)
         self.assertIs(type(warns[0].message), file_archive.UsageWarning)
         self.assertTrue(warns[0].message.args[0].endswith(
             "is a symbolic link, using target file instead"))
     with temp_dir() as d:
         os.symlink(self.t('file1.bin'), os.path.join(d, 'link'))
         with warnings.catch_warnings(record=True) as warns:
             self.store.add(d, {})
         test_warning(warns)
         with warnings.catch_warnings(record=True) as warns:
             self.store.add_file(os.path.join(d, 'link'), {})
         test_warning(warns)
예제 #12
0
    def test_external_symlink(self):
        def test_warning(warns):
            self.assertEqual(len(warns), 1)
            self.assertIs(type(warns[0].message), file_archive.UsageWarning)
            self.assertTrue(warns[0].message.args[0].endswith(
                "is a symbolic link, using target file instead"))

        with temp_dir() as d:
            os.symlink(self.t('file1.bin'), os.path.join(d, 'link'))
            with warnings.catch_warnings(record=True) as warns:
                self.store.add(d, {})
            test_warning(warns)
            with warnings.catch_warnings(record=True) as warns:
                self.store.add_file(os.path.join(d, 'link'), {})
            test_warning(warns)
예제 #13
0
 def test_internal_symlink(self):
     with temp_dir() as d:
         shutil.copyfile(self.t('file1.bin'), os.path.join(d, 'file'))
         os.mkdir(os.path.join(d, 'dir'))
         os.symlink(os.path.join(d, 'file'), os.path.join(d, 'dir', 'link'))
         entry = self.store.add_directory(d, {})
         path = entry.filename
         c = (b'this is some\n'
              b'random content\n'
              b'note LF line endings\n')
         with open(os.path.join(path, 'file'), 'rb') as fp:
             self.assertEqual(fp.read(), c)
         with open(os.path.join(path, 'dir', 'link'), 'rb') as fp:
             self.assertEqual(fp.read(), c)
         self.assertTrue(os.path.islink(os.path.join(path, 'dir', 'link')))
         self.assertEqual(os.readlink(os.path.join(path, 'dir', 'link')),
                          '../file')
예제 #14
0
 def test_internal_symlink(self):
     with temp_dir() as d:
         shutil.copyfile(self.t('file1.bin'), os.path.join(d, 'file'))
         os.mkdir(os.path.join(d, 'dir'))
         os.symlink(os.path.join(d, 'file'), os.path.join(d, 'dir', 'link'))
         entry = self.store.add_directory(d, {})
         path = entry.filename
         c = (b'this is some\n'
              b'random content\n'
              b'note LF line endings\n')
         with open(os.path.join(path, 'file'), 'rb') as fp:
             self.assertEqual(fp.read(), c)
         with open(os.path.join(path, 'dir', 'link'), 'rb') as fp:
             self.assertEqual(fp.read(), c)
         self.assertTrue(os.path.islink(os.path.join(path, 'dir', 'link')))
         self.assertEqual(os.readlink(os.path.join(path, 'dir', 'link')),
                          '../file')
예제 #15
0
 def test_create_nonempty(self):
     with temp_dir() as d:
         with open(os.path.join(d, 'somefile'), 'wb') as fp:
             fp.write(b"I'm not empty\n")
         self.assertEqual(run_program(d, 'create'), 3)
예제 #16
0
 def test_create(self):
     with temp_dir() as d:
         self.assertEqual(run_program(d, 'create'), 0)
         self.assertTrue(os.path.isfile(os.path.join(d, 'database')))