File: test_failures.py

package info (click to toggle)
python-arpy 1.1.1-3~deb9u1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 172 kB
  • sloc: python: 441; makefile: 5
file content (41 lines) | stat: -rw-r--r-- 1,717 bytes parent folder | download | duplicates (5)
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
import arpy
import io
import unittest, os

class SimpleNames(unittest.TestCase):
	def test_not_ar_file(self):
		self.assertRaises(arpy.ArchiveFormatError, arpy.Archive,
			fileobj=io.BytesIO(b'not an ar file'))

	def test_bad_file_header_magic(self):
		bad_ar = b'!<arch>\nfile1/          1364071329  1000  100   100644  15        qq'
		ar = arpy.Archive(fileobj=io.BytesIO(bad_ar))
		self.assertRaises(arpy.ArchiveFormatError, ar.read_all_headers)

	def test_bad_file_header_short(self):
		bad_ar = b'!<arch>\nfile1/          1364071329  1000'
		ar = arpy.Archive(fileobj=io.BytesIO(bad_ar))
		self.assertRaises(arpy.ArchiveFormatError, ar.read_all_headers)

	def test_bad_file_header_nums(self):
		bad_ar = b'!<arch>\nfile1/          aaaa071329  1000  100   100644  15        `\n'
		ar = arpy.Archive(fileobj=io.BytesIO(bad_ar))
		self.assertRaises(arpy.ArchiveFormatError, ar.read_all_headers)

	def test_bad_file_size(self):
		bad_ar = b'!<arch>\nfile1/          1364071329  1000  100   100644  15        `\nabc'
		ar = arpy.Archive(fileobj=io.BytesIO(bad_ar))
		ar.read_all_headers()
		f1 = ar.archived_files[b'file1']
		self.assertRaises(arpy.ArchiveAccessError, f1.read)

	def test_bad_table_size(self):
		bad_ar = b'!<arch>\n//                                              10        `\n'
		ar = arpy.Archive(fileobj=io.BytesIO(bad_ar))
		self.assertRaises(arpy.ArchiveFormatError, ar.read_all_headers)

	def test_bad_table_reference(self):
		bad_ar = b'!<arch>\n//                                               0        `\n' \
			b'/9              1297730011  1000  1000  100644  0         `\n'
		ar = arpy.Archive(fileobj=io.BytesIO(bad_ar))
		self.assertRaises(arpy.ArchiveFormatError, ar.read_all_headers)