MCPcopy Index your code
hub / github.com/python/cpython / BaseTest

Class BaseTest

Lib/test/test_bz2.py:38–97  ·  view source on GitHub ↗

Base for other testcases.

Source from the content-addressed store, hash-verified

36 return bz2.decompress(data)
37
38class BaseTest(unittest.TestCase):
39 "Base for other testcases."
40
41 TEXT_LINES = [
42 b'root:x:0:0:root:/root:/bin/bash\n',
43 b'bin:x:1:1:bin:/bin:\n',
44 b'daemon:x:2:2:daemon:/sbin:\n',
45 b'adm:x:3:4:adm:/var/adm:\n',
46 b'lp:x:4:7:lp:/var/spool/lpd:\n',
47 b'sync:x:5:0:sync:/sbin:/bin/sync\n',
48 b'shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown\n',
49 b'halt:x:7:0:halt:/sbin:/sbin/halt\n',
50 b'mail:x:8:12:mail:/var/spool/mail:\n',
51 b'news:x:9:13:news:/var/spool/news:\n',
52 b'uucp:x:10:14:uucp:/var/spool/uucp:\n',
53 b'operator:x:11:0:operator:/root:\n',
54 b'games:x:12:100:games:/usr/games:\n',
55 b'gopher:x:13:30:gopher:/usr/lib/gopher-data:\n',
56 b'ftp:x:14:50:FTP User:/var/ftp:/bin/bash\n',
57 b'nobody:x:65534:65534:Nobody:/home:\n',
58 b'postfix:x:100:101:postfix:/var/spool/postfix:\n',
59 b'niemeyer:x:500:500::/home/niemeyer:/bin/bash\n',
60 b'postgres:x:101:102:PostgreSQL Server:/var/lib/pgsql:/bin/bash\n',
61 b'mysql:x:102:103:MySQL server:/var/lib/mysql:/bin/bash\n',
62 b'www:x:103:104::/var/www:/bin/false\n',
63 ]
64 TEXT = b''.join(TEXT_LINES)
65 DATA = b'BZh91AY&SY.\xc8N\x18\x00\x01>_\x80\x00\x10@\x02\xff\xf0\x01\x07n\x00?\xe7\xff\xe00\x01\x99\xaa\x00\xc0\x03F\x86\x8c#&\x83F\x9a\x03\x06\xa6\xd0\xa6\x93M\x0fQ\xa7\xa8\x06\x804hh\x12$\x11\xa4i4\xf14S\xd2<Q\xb5\x0fH\xd3\xd4\xdd\xd5\x87\xbb\xf8\x94\r\x8f\xafI\x12\xe1\xc9\xf8/E\x00pu\x89\x12]\xc9\xbbDL\nQ\x0e\t1\x12\xdf\xa0\xc0\x97\xac2O9\x89\x13\x94\x0e\x1c7\x0ed\x95I\x0c\xaaJ\xa4\x18L\x10\x05#\x9c\xaf\xba\xbc/\x97\x8a#C\xc8\xe1\x8cW\xf9\xe2\xd0\xd6M\xa7\x8bXa<e\x84t\xcbL\xb3\xa7\xd9\xcd\xd1\xcb\x84.\xaf\xb3\xab\xab\xad`n}\xa0lh\tE,\x8eZ\x15\x17VH>\x88\xe5\xcd9gd6\x0b\n\xe9\x9b\xd5\x8a\x99\xf7\x08.K\x8ev\xfb\xf7xw\xbb\xdf\xa1\x92\xf1\xdd|/";\xa2\xba\x9f\xd5\xb1#A\xb6\xf6\xb3o\xc9\xc5y\\\xebO\xe7\x85\x9a\xbc\xb6f8\x952\xd5\xd7"%\x89>V,\xf7\xa6z\xe2\x9f\xa3\xdf\x11\x11"\xd6E)I\xa9\x13^\xca\xf3r\xd0\x03U\x922\xf26\xec\xb6\xed\x8b\xc3U\x13\x9d\xc5\x170\xa4\xfa^\x92\xacDF\x8a\x97\xd6\x19\xfe\xdd\xb8\xbd\x1a\x9a\x19\xa3\x80ankR\x8b\xe5\xd83]\xa9\xc6\x08\x82f\xf6\xb9"6l$\xb8j@\xc0\x8a\xb0l1..\xbak\x83ls\x15\xbc\xf4\xc1\x13\xbe\xf8E\xb8\x9d\r\xa8\x9dk\x84\xd3n\xfa\xacQ\x07\xb1%y\xaav\xb4\x08\xe0z\x1b\x16\xf5\x04\xe9\xcc\xb9\x08z\x1en7.G\xfc]\xc9\x14\xe1B@\xbb!8`'
66 EMPTY_DATA = b'BZh9\x17rE8P\x90\x00\x00\x00\x00'
67 BAD_DATA = b'this is not a valid bzip2 file'
68
69 # Some tests need more than one block of data. The bz2 module does not
70 # support flushing a block during compression, so we must read in data until
71 # there are at least 2 blocks. Since different orderings of Python files may
72 # be compressed differently, we need to check the compression output for
73 # more than one bzip2 block header magic, a hex encoding of Pi
74 # (0x314159265359)
75 bz2_block_magic = bytes.fromhex('314159265359')
76 test_size = 0
77 BIG_TEXT = b''
78 BIG_DATA = b''
79 compressor = BZ2Compressor(1)
80 for fname in glob.glob(os.path.join(glob.escape(os.path.dirname(__file__)), '*.py')):
81 with open(fname, 'rb') as fh:
82 data = fh.read()
83 BIG_DATA += compressor.compress(data)
84 BIG_TEXT += data
85 # TODO(emmatyping): if it is impossible for a block header to cross
86 # multiple outputs, we can just search the output of each compress call
87 # which should be more efficient
88 if BIG_DATA.count(bz2_block_magic) > 1:
89 BIG_DATA += compressor.flush()
90 break
91
92 def setUp(self):
93 fd, self.filename = tempfile.mkstemp()
94 os.close(fd)
95

Callers

nothing calls this directly

Calls 9

escapeMethod · 0.80
openFunction · 0.50
joinMethod · 0.45
globMethod · 0.45
dirnameMethod · 0.45
readMethod · 0.45
compressMethod · 0.45
countMethod · 0.45
flushMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…