-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_rpic.py
62 lines (46 loc) · 1.59 KB
/
test_rpic.py
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
from os import path, rmdir, sys, unlink
import pytest
from rpic import Wallhaven
PLATFORM = sys.platform
@pytest.fixture(scope="session")
def haven():
return Wallhaven()
def test_url(haven):
url = (
"https://wallhaven.cc/search?categories=111&purity=100&"
"atleast=1920x1080&sorting=random&order=desc"
)
assert haven.url == url
def test_local_path(haven):
if PLATFORM == "win32":
assert haven.local_path == r"C:\Users\clamy\Pictures\wallpaper.jpg"
else:
assert haven.local_path == "/home/mohh/Pictures/wallpaper.jpg"
def test_wallpapers(haven):
if PLATFORM == "win32":
assert haven.wallpapers == r"C:\Users\clamy\Pictures\wallpapers"
else:
assert haven.wallpapers == "/home/mohh/Pictures/wallpapers"
def test_check_dir(haven):
tmp = "tmp"
assert not path.exists(tmp)
haven.check_dir(tmp)
assert path.exists(tmp)
assert path.isdir(tmp)
rmdir(tmp)
def test_download_image(haven):
url = "https://wallhaven.cc/images/layout/logo_sm.png"
image_loc = path.join(haven.img_folder, "test.jpg")
assert not path.exists(image_loc)
haven.download_image(image_loc, url)
assert path.exists(image_loc)
unlink(image_loc)
def test_download_image_bad_url(haven, capfd):
url = "https://webgenetics.com/wg_logo.png"
image_loc = path.join(haven.img_folder, "wg_logo.png")
assert not path.exists(image_loc)
with pytest.raises(SystemExit):
haven.download_image(image_loc, url)
output = capfd.readouterr()[0].strip()
assert output == "<Response [404]>"
unlink(image_loc)