-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_file_utils.py
More file actions
72 lines (54 loc) · 1.8 KB
/
test_file_utils.py
File metadata and controls
72 lines (54 loc) · 1.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import pytest
import os
import csv
from backend.config.paths import TMP_FILE_DIR
from backend.file_utils.csv_methods_writer import write_launch_info_to_csv
from backend.file_utils.files import reset_dirs, save_upload_file
from unittest.mock import Mock
from fastapi import UploadFile
from io import BytesIO
@pytest.mark.parametrize(
"filepaths",
[
([TMP_FILE_DIR + "/test"]),
([TMP_FILE_DIR + "/test1", TMP_FILE_DIR + "/test2"]),
],
)
def test_removing_tmp_files(filepaths):
for path in filepaths:
os.makedirs(path)
reset_dirs(filepaths)
for path in filepaths:
assert not os.path.exists(path)
def test_save_upload_file(tmp_path):
test_content = b"Hello, World!" * 1000
dest_path = tmp_path / "test.txt"
mock_file = BytesIO(test_content)
upload_file = Mock(spec=UploadFile)
upload_file.file = mock_file
save_upload_file(upload_file, str(dest_path))
assert dest_path.exists()
with open(dest_path, "rb") as f:
saved_content = f.read()
assert saved_content == test_content
def test_write_launch_info_to_csv(tmp_path):
output_file = tmp_path / "launch_info.csv"
parsed_methods = [
"ManuallyCollected.dll,BinSearchMain",
"ManuallyCollected.dll,BellmanFord",
"ManuallyCollected.dll,BinaryMaze1BFS",
]
write_launch_info_to_csv(
parsed_methods=parsed_methods, output_file=str(output_file)
)
assert output_file.exists()
with open(output_file, "r") as f:
reader = csv.reader(f)
rows = list(reader)
assert rows[0] == ["dll", "method"]
expected_data = [
["ManuallyCollected.dll", "BinSearchMain"],
["ManuallyCollected.dll", "BellmanFord"],
["ManuallyCollected.dll", "BinaryMaze1BFS"],
]
assert rows[1:] == expected_data