Context manager - creates a file, and deletes it on __exit__.
| 525 | |
| 526 | |
| 527 | class TempFile: |
| 528 | """Context manager - creates a file, and deletes it on __exit__.""" |
| 529 | |
| 530 | def __init__(self, filename, data=b""): |
| 531 | self.filename = filename |
| 532 | self.data = data |
| 533 | |
| 534 | def __enter__(self): |
| 535 | with open(self.filename, "wb") as f: |
| 536 | f.write(self.data) |
| 537 | |
| 538 | def __exit__(self, *args): |
| 539 | unlink(self.filename) |
| 540 | |
| 541 | |
| 542 | class FileTestCase(unittest.TestCase): |
no outgoing calls