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

Function setUpModule

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

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 12

compressFunction · 0.90
train_dictFunction · 0.90
randintMethod · 0.80
choiceMethod · 0.80
randrangeMethod · 0.80
openMethod · 0.45
abspathMethod · 0.45
readMethod · 0.45
subMethod · 0.45
decodeMethod · 0.45
joinMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…