Skip to content

Commit 06d10f0

Browse files
committed
-
1 parent a39c73c commit 06d10f0

File tree

2 files changed

+41
-2
lines changed

2 files changed

+41
-2
lines changed

source_py2/test_python_toolbox/test_temp_file_tools/test_create_temp_folder.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,25 @@ def test_basic():
5151
assert not file_path.exists()
5252
assert not file_path.is_file()
5353

54-
54+
def test_exception():
55+
try:
56+
with create_temp_folder() as tf1:
57+
assert isinstance(tf1, pathlib.Path)
58+
assert tf1.exists()
59+
assert tf1.is_dir()
60+
file_path = (tf1 / 'my_file')
61+
with file_path.open('w') as my_file:
62+
my_file.write('Woo hoo!')
63+
64+
assert file_path.exists()
65+
assert file_path.is_file()
66+
raise MyException
67+
except MyException:
68+
assert not tf1.exists()
69+
assert not tf1.is_dir()
70+
assert not file_path.exists()
71+
assert not file_path.is_file()
72+
5573
def test_without_pathlib():
5674
with create_temp_folder() as tf1:
5775
assert os.path.exists(str(tf1))

source_py3/test_python_toolbox/test_temp_file_tools/test_create_temp_folder.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717

1818
from python_toolbox.temp_file_tools import create_temp_folder
1919

20+
class MyException(Exception):
21+
pass
22+
2023

2124
def test_basic():
2225
with create_temp_folder() as tf1:
@@ -51,7 +54,25 @@ def test_basic():
5154
assert not file_path.exists()
5255
assert not file_path.is_file()
5356

54-
57+
def test_exception():
58+
try:
59+
with create_temp_folder() as tf1:
60+
assert isinstance(tf1, pathlib.Path)
61+
assert tf1.exists()
62+
assert tf1.is_dir()
63+
file_path = (tf1 / 'my_file')
64+
with file_path.open('w') as my_file:
65+
my_file.write('Woo hoo!')
66+
67+
assert file_path.exists()
68+
assert file_path.is_file()
69+
raise MyException
70+
except MyException:
71+
assert not tf1.exists()
72+
assert not tf1.is_dir()
73+
assert not file_path.exists()
74+
assert not file_path.is_file()
75+
5576
def test_without_pathlib():
5677
with create_temp_folder() as tf1:
5778
assert os.path.exists(str(tf1))

0 commit comments

Comments
 (0)