Exemplo n.º 1
0
    def _create_cpio(project, repository, arch, package, **kwargs):
        """Creates and returns a CpioArchive object.

        Keyword arguments:
        kwargs -- optional parameters for the http request (like query
                  parameters)

        """
        f = BinaryList._perform_request(project, repository, arch, package,
                                        **kwargs)
        return CpioArchive(fobj=f)
Exemplo n.º 2
0
 def test23(self):
     """test CpioArchive class"""
     fname = self.fixture_file('cpio_archive.cpio')
     archive = CpioArchive(filename=fname)
     filenames = ['bar', 'file1', 'foo']
     contents = ['File bar\nhas some\ncontent...\n',
                 'This is yet\nanother\nfile.\n',
                 'file foo\n']
     for archive_file in archive:
         self.assertEqual(archive_file.hdr.name, filenames.pop(0))
         self.assertEqual(archive_file.read(), contents.pop(0))
     self.assertEqual(archive.filenames(), ['bar', 'file1', 'foo'])
     self.assertEqual(len(archive.files()), 3)
     # read file bar again (no content because the whole file was already
     # read)
     archive_file = archive.find('bar')
     self.assertIsNotNone(archive_file)
     self.assertEqual(archive_file.read(), '')
     # try to find non existent file
     self.assertIsNone(archive.find('unknown'))
     self.assertEqual(archive.magic, '070701')
Exemplo n.º 3
0
 def test25(self):
     """test CpioArchive class unseekable input 2"""
     fname = self.fixture_file('cpio_archive.cpio')
     sio = StringIO(open(fname, 'r').read())
     sio.seek = None
     archive = CpioArchive(fobj=sio)
     # get the second file in the archive
     archive_file = archive.find('file1')
     self.assertIsNotNone(archive_file)
     self.assertEqual(archive_file.read(4), 'This')
     # now get the first file in the archive
     archive_file = archive.find('bar')
     self.assertIsNotNone(archive_file)
     # a read raises an IOError because we cannot seek back
     self.assertRaises(IOError, archive_file.read)
     # read rest from the second file
     archive_file = archive.find('file1')
     self.assertIsNotNone(archive_file)
     self.assertEqual(archive_file.read(), ' is yet\nanother\nfile.\n')
     # finally read the last file
     archive_file = archive.find('foo')
     self.assertIsNotNone(archive_file)
     self.assertEqual(archive_file.read(), 'file foo\n')
     self.assertEqual(archive.magic, '070701')
Exemplo n.º 4
0
 def test24(self):
     """test CpioArchive class unseekable input 1"""
     fname = self.fixture_file('cpio_archive.cpio')
     sio = StringIO(open(fname, 'r').read())
     sio.seek = None
     archive = CpioArchive(fobj=sio)
     filenames = ['bar', 'file1', 'foo']
     contents = ['File bar\nhas some\ncontent...\n',
                 'This is yet\nanother\nfile.\n',
                 'file foo\n']
     for archive_file in archive:
         self.assertEqual(archive_file.hdr.name, filenames.pop(0))
         self.assertEqual(archive_file.read(), contents.pop(0))
     self.assertEqual(archive.filenames(), ['bar', 'file1', 'foo'])
     self.assertEqual(len(archive.files()), 3)
     # read file bar again
     archive_file = archive.find('bar')
     self.assertIsNotNone(archive_file)
     # the empty str because the file was already completely read
     # => no seek is made and no IOError is raised
     self.assertEqual(archive_file.read(), '')
     # try to find non existent file
     self.assertIsNone(archive.find('unknown'))
     self.assertEqual(archive.magic, '070701')