-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtests.py
More file actions
77 lines (58 loc) · 2.15 KB
/
tests.py
File metadata and controls
77 lines (58 loc) · 2.15 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
73
74
75
76
77
import os
import subprocess
import pytest
from downloader import get_images
data = "test_data"
target = "test_target"
def test_happy_paths():
path = f"{data}/correct_paths.txt"
target_path = target
faulty = get_images(path, target_path)
assert not faulty
def test_non_images_paths():
path = f"{data}/correct_paths_with_non_images.txt"
target_path = target
faulty = get_images(path, target_path)
assert not faulty
def test_broken_paths():
path = f"{data}/broken_paths.txt"
target_path = target
faulty = get_images(path, target_path)
assert faulty
def test_broken_file_permissions():
"""Testing this is not simple since git doesn't sync file permissions. So we need to create the file the first time
after removing it (if it was checked in by accident).
Test included to document expected behaviour.
"""
file_path = os.path.join(data, "temp_file.txt")
dir_path = target
try:
os.remove(file_path) # Remove if present
except FileNotFoundError:
pass
with open(file_path, "w") as out_file:
out_file.write("Some content.")
os.chmod(file_path, mode=0o111) # Execute-only
with pytest.raises(PermissionError):
get_images(file_path, dir_path)
def test_broken_dir_permissions():
"""Testing this is not simple since git doesn't sync dir permissions. So we need to create the dir the first time
after removing it (if it was checked in by accident).
Test included to document expected behaviour.
"""
file_path = os.path.join(data, "correct_paths.txt")
dir_path = os.path.join(target, "temp_dir")
try:
os.rmdir(dir_path) # Remove if present
except FileNotFoundError:
pass
os.mkdir(dir_path, mode=0o111) # Execute-only
with pytest.raises(PermissionError):
get_images(file_path, dir_path)
def test_cmd_line_execution():
subprocess.run(["python3", "--version"])
completed = subprocess.run(["python3",
"downloader.py",
"-f=test_data/correct_paths.txt",
"-d=test_target"])
assert completed.returncode == 0