Skip to content

Commit

Permalink
test CloseableNamedTemporaryFile
Browse files Browse the repository at this point in the history
  • Loading branch information
blattm committed Dec 7, 2023
1 parent 1ba1671 commit f81eddf
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions tests/util/test_closeable_named_temporary_file.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import os
from decompiler.util.closeable_named_temporary_file import CloseableNamedTemporaryFile


class TestCloseableNamedTemporaryFile:
def test_usage_after_closing(self):
with CloseableNamedTemporaryFile(mode = "w") as file:
file.write("test")
file.close()
with open(file.name, "r") as reopened_file:
assert reopened_file.read() == "test"

def test_deletion_with_close(self):
with CloseableNamedTemporaryFile(mode = "w") as file:
file.close()
assert not os.path.exists(file.name)

def test_deletion_without_close(self):
with CloseableNamedTemporaryFile(mode = "w") as file:
pass
assert not os.path.exists(file.name)

def test_close_after_delete(self):
with CloseableNamedTemporaryFile(mode = "w") as file:
pass
file.close()

0 comments on commit f81eddf

Please sign in to comment.