1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
|
import arpy
import io
import unittest, os
class SimpleNames(unittest.TestCase):
def test_single_name(self):
ar = arpy.Archive(os.path.join(os.path.dirname(__file__), 'normal.ar'))
ar.read_all_headers()
self.assertEqual([b'short'],
list(ar.archived_files.keys()))
self.assertEqual(1, len(ar.headers))
ar.close()
def test_header_description(self):
ar = arpy.Archive(os.path.join(os.path.dirname(__file__), 'normal.ar'))
header = ar.read_next_header()
self.assertTrue(repr(header).startswith('<ArchiveFileHeader'))
ar.close()
def test_empty_ar(self):
ar = arpy.Archive(os.path.join(os.path.dirname(__file__), 'empty.ar'))
ar.read_all_headers()
self.assertEqual([],
list(ar.archived_files.keys()))
self.assertEqual(0, len(ar.headers))
ar.close()
def test_symbols(self):
ar = arpy.Archive(os.path.join(os.path.dirname(__file__), 'sym.ar'))
syms = ar.read_next_header()
self.assertEqual(arpy.HEADER_GNU_SYMBOLS, syms.type)
self.assertEqual(4, syms.size)
ao = ar.read_next_header()
self.assertEqual(arpy.HEADER_NORMAL, ao.type)
self.assertEqual(0, ao.size)
self.assertEqual(b"a.o", ao.name)
ar.close()
def test_fileobj(self):
data = open(os.path.join(os.path.dirname(__file__), 'normal.ar'), "rb").read()
ar = arpy.Archive(fileobj=io.BytesIO(data))
ar.read_all_headers()
self.assertEqual([b'short'],
list(ar.archived_files.keys()))
self.assertEqual(1, len(ar.headers))
ar.close()
class ArchiveIteration(unittest.TestCase):
def test_iteration(self):
ar = arpy.Archive(os.path.join(os.path.dirname(__file__), 'normal.ar'))
ar_iterator = iter(ar)
short = ar_iterator.next()
self.assertEqual(b'short', short.header.name)
self.assertRaises(StopIteration, ar_iterator.next)
ar.close()
|