File tree Expand file tree Collapse file tree 2 files changed +41
-2
lines changed
source_py2/test_python_toolbox/test_temp_file_tools
source_py3/test_python_toolbox/test_temp_file_tools Expand file tree Collapse file tree 2 files changed +41
-2
lines changed Original file line number Diff line number Diff 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+
5573def test_without_pathlib ():
5674 with create_temp_folder () as tf1 :
5775 assert os .path .exists (str (tf1 ))
Original file line number Diff line number Diff line change 1717
1818from python_toolbox .temp_file_tools import create_temp_folder
1919
20+ class MyException (Exception ):
21+ pass
22+
2023
2124def 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+
5576def test_without_pathlib ():
5677 with create_temp_folder () as tf1 :
5778 assert os .path .exists (str (tf1 ))
You can’t perform that action at this time.
0 commit comments