1- import shutil
2-
3- import pytest , os , csv
1+ import pytest
2+ import os
3+ import csv
44
55from backend .config .paths import TMP_FILE_DIR
66from backend .file_utils .csv_methods_writer import write_launch_info_to_csv
1313@pytest .mark .parametrize (
1414 "filepaths" ,
1515 [
16- ([TMP_FILE_DIR + "/test0 " ]),
16+ ([TMP_FILE_DIR + "/test " ]),
1717 ([TMP_FILE_DIR + "/test1" , TMP_FILE_DIR + "/test2" ]),
1818 ],
1919)
@@ -25,37 +25,37 @@ def test_removing_tmp_files(filepaths):
2525 assert not os .path .exists (path )
2626
2727
28- def test_save_upload_file ():
28+ def test_save_upload_file (tmp_path ):
2929 test_content = b"Hello, World!" * 1000
30- upload_dir = TMP_FILE_DIR + "/test_save_upload/"
31- dest_path = upload_dir + "test.txt"
30+ dest_path = tmp_path / "test.txt"
3231
3332 mock_file = BytesIO (test_content )
3433 upload_file = Mock (spec = UploadFile )
3534 upload_file .file = mock_file
3635
37- save_upload_file (upload_file , dest_path )
36+ save_upload_file (upload_file , str ( dest_path ) )
3837
39- assert os . path . exists (dest_path )
38+ assert dest_path . exists ()
4039 with open (dest_path , "rb" ) as f :
4140 saved_content = f .read ()
42- shutil . rmtree ( upload_dir )
41+
4342 assert saved_content == test_content
4443
4544
46- def test_write_launch_info_to_csv ():
47- upload_dir = TMP_FILE_DIR + "/test_write_launch_info_to_csv/"
48- os .makedirs (upload_dir )
49- output_file = upload_dir + "launch_info.csv"
45+ def test_write_launch_info_to_csv (tmp_path ):
46+ output_file = tmp_path / "launch_info.csv"
47+
5048 parsed_methods = [
5149 "ManuallyCollected.dll,BinSearchMain" ,
5250 "ManuallyCollected.dll,BellmanFord" ,
5351 "ManuallyCollected.dll,BinaryMaze1BFS" ,
5452 ]
5553
56- write_launch_info_to_csv (parsed_methods = parsed_methods , output_file = output_file )
54+ write_launch_info_to_csv (
55+ parsed_methods = parsed_methods , output_file = str (output_file )
56+ )
5757
58- assert os . path . exists (output_file )
58+ assert output_file . exists ()
5959
6060 with open (output_file , "r" ) as f :
6161 reader = csv .reader (f )
@@ -68,5 +68,5 @@ def test_write_launch_info_to_csv():
6868 ["ManuallyCollected.dll" , "BellmanFord" ],
6969 ["ManuallyCollected.dll" , "BinaryMaze1BFS" ],
7070 ]
71- shutil . rmtree ( upload_dir )
71+
7272 assert rows [1 :] == expected_data
0 commit comments