def test_temp_file_removes(self): foo = NamedTemporaryFile(suffix='foo.txt', delete=True) full_path = foo.temporary_file_path() path, name = os.path.split(full_path) self.assertRegexpMatches(name, r'\w+foo.txt') foo.close() self.assertFalse(os.path.isfile(full_path))
def test_temp_file_removes_manually(self): foo = NamedTemporaryFile(suffix='foo.txt', delete=False) full_path = foo.temporary_file_path() os.remove(full_path) self.assertFalse(os.path.isfile(full_path)) # although removed, shouldn't raise an error foo.close()
def test_temp_file_keeps(self): foo = NamedTemporaryFile(suffix='foo.txt', delete=False) full_path = foo.temporary_file_path() foo.close() self.assertTrue(os.path.isfile(full_path))