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

Function _create_file_shallow_equal

Lib/test/test_filecmp.py:12–22  ·  view source on GitHub ↗

create a file with the same size and mtime but different content.

(template_path, new_path)

Source from the content-addressed store, hash-verified

10
11
12def _create_file_shallow_equal(template_path, new_path):
13 """create a file with the same size and mtime but different content."""
14 shutil.copy2(template_path, new_path)
15 with open(new_path, 'r+b') as f:
16 next_char = bytearray(f.read(1))
17 next_char[0] = (next_char[0] + 1) % 256
18 f.seek(0)
19 f.write(next_char)
20 shutil.copystat(template_path, new_path)
21 assert os.stat(new_path).st_size == os.stat(template_path).st_size
22 assert os.stat(new_path).st_mtime == os.stat(template_path).st_mtime
23
24class FileCompareTestCase(unittest.TestCase):
25 def setUp(self):

Callers 2

setUpMethod · 0.85
setUpMethod · 0.85

Calls 5

openFunction · 0.50
readMethod · 0.45
seekMethod · 0.45
writeMethod · 0.45
statMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…