1+ from pathlib import Path
12from datetime import datetime
23
34import pytest
@@ -71,7 +72,7 @@ def test_create_events_string():
7172
7273
7374def test_save_file (tmp_path ):
74- f1 = tmp_path / "test.png"
75+ filename = tmp_path / "test.png"
7576 res = takeScreenshot (
7677 date = datetime .today (),
7778 imageScale = 2.44 ,
@@ -82,13 +83,47 @@ def test_save_file(tmp_path):
8283 height = 1200 ,
8384 display = True ,
8485 )
85- save_file (res , f1 , overwrite = False )
86- assert f1 . exists ()
86+ saved_file = save_file (res , filename , overwrite = False )
87+ assert saved_file == filename
8788 with pytest .raises (FileExistsError , match = "already exists" ):
88- save_file (res , f1 , overwrite = False )
89- save_file (res , f1 , overwrite = True )
90- assert f1 .exists ()
89+ save_file (res , filename , overwrite = False )
90+ save_file (res , filename , overwrite = True )
9191
92- f2 = tmp_path / "test2.png"
93- save_file (res , str (f2 ), overwrite = False )
94- assert f2 .exists ()
92+
93+ def test_save_file_cleans (tmp_path ):
94+ # Clean the filename for Windows filepaths
95+ filename = tmp_path / ":test.png"
96+ clean_filename = str (filename ).replace (":test.png" , "_test.png" )
97+ res = takeScreenshot (
98+ date = datetime .today (),
99+ imageScale = 2.44 ,
100+ layers = "[10,1,100]" ,
101+ x0 = 0 ,
102+ y0 = 0 ,
103+ width = 1920 ,
104+ height = 1200 ,
105+ display = True ,
106+ )
107+ saved_file = save_file (res , str (filename ))
108+ assert not filename .exists ()
109+ assert saved_file == Path (clean_filename )
110+
111+
112+ def test_save_file_expands ():
113+ # Check that ~/ expands
114+ filename = "~/:test.png"
115+ clean_filename = str (filename ).replace (":" , "_" )
116+ res = takeScreenshot (
117+ date = datetime .today (),
118+ imageScale = 2.44 ,
119+ layers = "[10,1,100]" ,
120+ x0 = 0 ,
121+ y0 = 0 ,
122+ width = 1920 ,
123+ height = 1200 ,
124+ display = True ,
125+ )
126+ saved_file = save_file (res , filename )
127+ saved_file .unlink ()
128+ assert not Path (filename ).exists ()
129+ assert saved_file == Path (clean_filename ).expanduser ().resolve ()
0 commit comments