def test18(self): """test NewAsciiWriter's append method""" fname = self.fixture_file('foo') st = os.stat(fname) sio = StringIO() archive_writer = NewAsciiWriter(sio) archive_writer.append(fname) self.assertEqual(archive_writer._bytes_written, 128) fname = self.fixture_file('new_ascii_writer_foo_header') # we can only compare the sizes because the inode, dev_maj and dev_min # of the foo file has changed (because it was copied to a # tmpdir - that's how our testsuite works...) self.assertEqual(len(sio.getvalue()), len(open(fname, 'r').read())) # check manually... sio.seek(0, os.SEEK_SET) f = FileWrapper(fobj=sio) archive_reader = NewAsciiReader(f) hdr = archive_reader.next_header() self.assertEqual(hdr.magic, '070701') # self.assertEqual(hdr.ino, 1788176) self.assertEqual(hdr.mode, st.st_mode) self.assertEqual(hdr.uid, st.st_uid) self.assertEqual(hdr.gid, st.st_gid) self.assertEqual(hdr.nlink, 1) self.assertEqual(hdr.mtime, int(st.st_mtime)) self.assertEqual(hdr.filesize, 9) # self.assertEqual(hdr.dev_maj, 8) # self.assertEqual(hdr.dev_min, 10) self.assertEqual(hdr.rdev_maj, 0) self.assertEqual(hdr.rdev_min, 0) self.assertEqual(hdr.namesize, 4) self.assertEqual(hdr.chksum, 0) self.assertEqual(hdr.name, 'foo')
def test20(self): """test NewAsciiWriter's _append_trailer method""" sio = StringIO() archive_writer = NewAsciiWriter(sio) archive_writer._append_trailer() self.assertEqual(archive_writer._bytes_written, 124) self.assertEqualFile(sio.getvalue(), 'new_ascii_writer_trailer_header')
def test19(self): """test NewAsciiWriter's append method (fobj)""" fname = self.fixture_file('foo') sio_fobj = StringIO(open(fname, 'r').read()) sio = StringIO() archive_writer = NewAsciiWriter(sio) archive_writer.append('foo', fobj=sio_fobj) self.assertEqual(archive_writer._bytes_written, 128) fname = self.replace_uid_gid('new_ascii_writer_foo_header_default') self.assertEqualFile(sio.getvalue(), fname)
def test22(self): """test NewAsciiWriter's copyout method""" # write a complete cpio archive f = StringIO() archive_writer = NewAsciiWriter(f) sio = StringIO('This is a small\ntest file.\n') archive_writer.append('test1', fobj=sio) sio = StringIO('Yet another\ntest file.\n') archive_writer.append('test2', fobj=sio) sio = StringIO('The last test file.\n') archive_writer.append('last_file', fobj=sio) archive_writer.copyout() self.assertEqual(archive_writer._bytes_written, 1024) fname = self.replace_uid_gid('new_ascii_writer_sio.cpio') self.assertEqualFile(f.getvalue(), fname)
def test21(self): """test NewAsciiWriter's copyout method""" fname = self.fixture_file('foo') sio_fobj = StringIO(open(fname, 'r').read()) sio = StringIO() archive_writer = NewAsciiWriter(sio) archive_writer.append('foo', fobj=sio_fobj) archive_writer.copyout() self.assertEqual(archive_writer._bytes_written, 512) fname = self.fixture_file('new_ascii_writer.cpio') self.assertEqual(len(sio.getvalue()), len(open(fname, 'r').read()))