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

Function write_test_file

Lib/test/test_shutil.py:84–100  ·  view source on GitHub ↗

Create a test file with an arbitrary size and random text content.

(path, size)

Source from the content-addressed store, hash-verified

82 fp.write(content)
83
84def write_test_file(path, size):
85 """Create a test file with an arbitrary size and random text content."""
86 def chunks(total, step):
87 assert total >= step
88 while total > step:
89 yield step
90 total -= step
91 if total:
92 yield total
93
94 bufsize = min(size, 8192)
95 chunk = b"".join([random.choice(string.ascii_letters).encode()
96 for i in range(bufsize)])
97 with open(path, 'wb') as f:
98 for csize in chunks(size, bufsize):
99 f.write(chunk)
100 assert os.path.getsize(path) == size
101
102def read_file(path, binary=False):
103 """Return contents from a file located at *path*.

Callers 2

setUpClassMethod · 0.85
setUpClassMethod · 0.85

Calls 6

chunksFunction · 0.85
choiceMethod · 0.80
openFunction · 0.50
joinMethod · 0.45
encodeMethod · 0.45
writeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…