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

Class TempFile

Lib/test/test_lzma.py:522–534  ·  view source on GitHub ↗

Context manager - creates a file, and deletes it on __exit__.

Source from the content-addressed store, hash-verified

520
521
522class TempFile:
523 """Context manager - creates a file, and deletes it on __exit__."""
524
525 def __init__(self, filename, data=b""):
526 self.filename = filename
527 self.data = data
528
529 def __enter__(self):
530 with open(self.filename, "wb") as f:
531 f.write(self.data)
532
533 def __exit__(self, *args):
534 unlink(self.filename)
535
536
537class FileTestCase(unittest.TestCase):

Callers 11

test_init_modeMethod · 0.70
test_closeMethod · 0.70
test_filenoMethod · 0.70
test_read_from_fileMethod · 0.70
test_filenameMethod · 0.70

Calls

no outgoing calls

Tested by 11

test_init_modeMethod · 0.56
test_closeMethod · 0.56
test_filenoMethod · 0.56
test_read_from_fileMethod · 0.56
test_filenameMethod · 0.56

Used in the wild real call sites across dependent graphs

searching dependent graphs…