MCPcopy Index your code
hub / github.com/RustPython/RustPython / setUpModule

Function setUpModule

Lib/test/test_zstd.py:77–132  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

75
76
77def setUpModule():
78 # uncompressed size 130KB, more than a zstd block.
79 # with a frame epilogue, 4 bytes checksum.
80 global DAT_130K_D
81 DAT_130K_D = bytes([random.randint(0, 127) for _ in range(130*_1K)])
82
83 global DAT_130K_C
84 DAT_130K_C = compress(DAT_130K_D, options={CompressionParameter.checksum_flag:1})
85
86 global DECOMPRESSED_DAT
87 DECOMPRESSED_DAT = b'abcdefg123456' * 1000
88
89 global COMPRESSED_DAT
90 COMPRESSED_DAT = compress(DECOMPRESSED_DAT)
91
92 global DECOMPRESSED_100_PLUS_32KB
93 DECOMPRESSED_100_PLUS_32KB = b'a' * (100 + 32*_1K)
94
95 global COMPRESSED_100_PLUS_32KB
96 COMPRESSED_100_PLUS_32KB = compress(DECOMPRESSED_100_PLUS_32KB)
97
98 global SKIPPABLE_FRAME
99 SKIPPABLE_FRAME = (0x184D2A50).to_bytes(4, byteorder='little') + \
100 (32*_1K).to_bytes(4, byteorder='little') + \
101 b'a' * (32*_1K)
102
103 global THIS_FILE_BYTES, THIS_FILE_STR
104 with io.open(os.path.abspath(__file__), 'rb') as f:
105 THIS_FILE_BYTES = f.read()
106 THIS_FILE_BYTES = re.sub(rb'\r?\n', rb'\n', THIS_FILE_BYTES)
107 THIS_FILE_STR = THIS_FILE_BYTES.decode('utf-8')
108
109 global COMPRESSED_THIS_FILE
110 COMPRESSED_THIS_FILE = compress(THIS_FILE_BYTES)
111
112 global COMPRESSED_BOGUS
113 COMPRESSED_BOGUS = DECOMPRESSED_DAT
114
115 # dict data
116 words = [b'red', b'green', b'yellow', b'black', b'withe', b'blue',
117 b'lilac', b'purple', b'navy', b'glod', b'silver', b'olive',
118 b'dog', b'cat', b'tiger', b'lion', b'fish', b'bird']
119 lst = []
120 for i in range(300):
121 sample = [b'%s = %d' % (random.choice(words), random.randrange(100))
122 for j in range(20)]
123 sample = b'\n'.join(sample)
124
125 lst.append(sample)
126 global SAMPLES
127 SAMPLES = lst
128 assert len(SAMPLES) > 10
129
130 global TRAINED_DICT
131 TRAINED_DICT = train_dict(SAMPLES, 3*_1K)
132 assert len(TRAINED_DICT.dict_content) <= 3*_1K
133
134

Callers

nothing calls this directly

Calls 13

compressFunction · 0.90
train_dictFunction · 0.90
lenFunction · 0.85
randintMethod · 0.80
to_bytesMethod · 0.80
choiceMethod · 0.80
randrangeMethod · 0.80
openMethod · 0.45
readMethod · 0.45
subMethod · 0.45
decodeMethod · 0.45
joinMethod · 0.45

Tested by

no test coverage detected