Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ksh-b committed Jun 22, 2024
1 parent 47c490a commit 251e37e
Showing 1 changed file with 58 additions and 60 deletions.
118 changes: 58 additions & 60 deletions tests/test_wanda.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import os.path
import re
import unittest
from pathlib import Path

import pytest

import wanda.sources as source
import wanda.utils.common_utils as common
import wanda.utils.image_utils as image
from sources.extractor import *


# These tests should be compatible with ci runners
Expand All @@ -26,127 +25,126 @@ def test_conn_test(self):
self.assertTrue(common.is_connected())

def test_local(self):
self.assertRaises(SystemExit, source.local, None)
self.assertRaises(SystemExit, source.local, "")
self.assertRaises(SystemExit, local, None)
self.assertRaises(SystemExit, local, "")

def test_wallhaven(self):
url = "https://w.wallhaven.cc/full/"

response = source.wallhaven(None)
response = wallhaven(None)
self.assert_starts_with(response, url)

response = source.wallhaven("")
response = wallhaven("")
self.assert_starts_with(response, url)

response = source.wallhaven(self.good_search)
response = wallhaven(self.good_search)
self.assert_starts_with(response, url)

self.assertRaises(SystemExit, source.wallhaven, self.bad_search)
self.assertRaises(SystemExit, wallhaven, self.bad_search)

def test_reddit(self):
url = "https://i.redd.it/"

self.assertIn("wallpaper", source.suggested_subreddits())
self.assertIn("wallpaper", suggested_subreddits())

response = source.reddit(search=None)
response = reddit(search=None)
self.assert_starts_with(response, url)

response = source.reddit("")
response = reddit("")
self.assert_starts_with(response, url)

response = source.reddit(self.good_search)
response = reddit(self.good_search)
self.assertNotNone(response, "^https?://")

response = source.reddit("wallpaper@halflife")
response = reddit("wallpaper@halflife")
self.assertNotNone(response, "^https?://")

self.assertRaises(SystemExit, source.reddit, search=self.bad_search)
self.assertRaises(SystemExit, reddit, search=self.bad_search)

def test_imgur(self):
url = "https://rimgo.projectsegfau.lt/"
url = "https://rimgo.eu.projectsegfau.lt"

self.assertRaises(SystemExit, source.imgur, None)
self.assertRaises(SystemExit, imgur, None)

self.assertRaises(SystemExit, source.imgur, "")
self.assertRaises(SystemExit, imgur, "")

response = source.imgur(search="jmVC8")
response = imgur(search="jmVC8")
self.assert_starts_with(response, url)

self.assertRaises(SystemExit, source.imgur, self.bad_search)
self.assertRaises(SystemExit, imgur, self.bad_search)

def test_fourchan(self):
url = "^(https?://archive-media.palanq.win/|https?://i.4cdn.org)"

response = source.fourchan(None)
response = fourchan(None)
self.assertNotNone(response, url)

response = source.fourchan("")
response = fourchan("")
self.assertNotNone(response, url)

response = source.fourchan("phone")
response = fourchan("phone")
self.assertNotNone(response, url)

self.assertRaises(SystemExit, source.fourchan, self.bad_search)
self.assertRaises(SystemExit, fourchan, self.bad_search)

def test_artstation_any(self):
url = self.artstation_cdn
response = source.artstation_any(None)
response = artstation_any(None)
self.assertNotNone(response, url)

response = source.artstation_any("")
response = artstation_any("")
self.assertNotNone(response, url)

response = source.artstation_any(self.good_search)
response = artstation_any(self.good_search)
self.assertNotNone(response, url)

self.assertRaises(SystemExit, source.artstation_any, self.bad_search)
self.assertRaises(SystemExit, artstation_any, self.bad_search)

def test_artstation_prints(self):
url = self.artstation_cdn
response = source.artstation_prints(None)
response = artstation_prints(None)
self.assertNotNone(response, url)

response = source.artstation_prints("")
response = artstation_prints("")
self.assertNotNone(response, url)

response = source.artstation_prints(self.good_search)
response = artstation_prints(self.good_search)
self.assertNotNone(response, url)

self.assertRaises(SystemExit, source.artstation_prints, self.bad_search)
self.assertRaises(SystemExit, artstation_prints, self.bad_search)

def test_artstation_artist(self):
url = self.artstation_cdn

self.assertRaises(SystemExit, source.artstation_artist, None)
self.assertRaises(SystemExit, source.artstation_artist, "")
self.assertRaises(SystemExit, source.artstation_artist, self.bad_search)
self.assertRaises(SystemExit, artstation_artist, None)
self.assertRaises(SystemExit, artstation_artist, "")
self.assertRaises(SystemExit, artstation_artist, self.bad_search)

response = source.artstation_artist("tohad")
response = artstation_artist("tohad")
self.assertNotNone(response, url)

def test_earthview(self):
url = "https://www.gstatic.com/prettyearth/assets/full/"
response = source.earthview(None)
self.assert_starts_with(response, url)
response = earthview(None)
self.assertIsNotNone(response)

def test_musicbrainz(self):
self.assertNotIsInstance(source.musicbrainz, str, "NoArtistFoo-NoAlbumBar")
self.assertNotIsInstance(musicbrainz, str, "NoArtistFoo-NoAlbumBar")

source.musicbrainz("Coldplay-Parachutes")
musicbrainz("Coldplay-Parachutes")

def test_waifuim(self):
url = "https://cdn.waifu.im/"

response = source.waifuim(None)
response = waifuim(None)
self.assert_starts_with(response, url)

response = source.waifuim("")
response = waifuim("")
self.assert_starts_with(response, url)

response = source.waifuim("uniform")
response = waifuim("uniform")
self.assert_starts_with(response, url)

self.assertRaises(SystemExit, source.waifuim, self.bad_search)
self.assertRaises(SystemExit, waifuim, self.bad_search)


# These tests would need actual device
Expand All @@ -155,48 +153,48 @@ class AdvancedTest(unittest.TestCase):
good_search = "nature"

def test_size(self):
self.assertEqual(type(source.size()), tuple)
self.assertEqual(type(size()), tuple)

def test_set_local(self):
folder = f"{str(Path.home())}/wanda"
path = source.get_dl_path()
path = source.download(path, "https://i.imgur.com/bBNy18H.jpeg")
path = get_dl_path()
path = common.download(path, "https://i.imgur.com/bBNy18H.jpeg")
self.assertTrue(os.path.exists(path))
image.set_wp(source.local(folder), True, True)
image.set_wp(local(folder), True, True)

def test_set_wallhaven(self):
image.set_wp(source.wallhaven(self.good_search), True, True)
image.set_wp(wallhaven(self.good_search), True, True)

def test_set_artstation(self):
image.set_wp(source.artstation_artist("tohad"), True, True)
image.set_wp(artstation_artist("tohad"), True, True)

image.set_wp(source.artstation_prints(self.good_search), True, True)
image.set_wp(artstation_prints(self.good_search), True, True)

image.set_wp(source.artstation_any(self.good_search), True, True)
image.set_wp(artstation_any(self.good_search), True, True)

def test_set_reddit(self):
image.set_wp(source.reddit(self.good_search), True, True)
image.set_wp(reddit(self.good_search), True, True)

image.set_wp(source.reddit("wallpaper@halflife"), True, True)
image.set_wp(reddit("wallpaper@halflife"), True, True)

@staticmethod
def test_set_imgur():
image.set_wp(source.imgur("jmVC8"), True, True)
image.set_wp(imgur("jmVC8"), True, True)

@staticmethod
def test_set_earthview():
image.set_wp(source.earthview(""), True, True)
image.set_wp(earthview(""), True, True)

@staticmethod
def test_set_waifuim():
image.set_wp(source.waifuim("uniform"), True, True)
image.set_wp(waifuim("uniform"), True, True)

@staticmethod
def test_set_fourchan():
image.set_wp(source.fourchan("mobile"), True, True)
image.set_wp(fourchan("mobile"), True, True)

def test_set_fivehundredpx(self):
image.set_wp(source.fivehundredpx(self.good_search), True, True)
# def test_set_fivehundredpx(self):
# image.set_wp(fivehundredpx(self.good_search), True, True)


if __name__ == "__main__":
Expand Down

0 comments on commit 251e37e

Please sign in to comment.