summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--module/InitHomeDir.py3
-rwxr-xr-xpyLoadCore.py10
-rw-r--r--tests/CrypterPluginTester.py18
-rw-r--r--tests/HosterPluginTester.py33
-rw-r--r--tests/helper/PluginTester.py4
-rw-r--r--tests/helper/Stubs.py9
-rwxr-xr-xtests/hosterlinks.txt4
-rwxr-xr-xtests/plugin_tests.sh4
-rwxr-xr-xtests/sloccount.sh2
-rw-r--r--tests/test_api.py24
-rw-r--r--tests/test_backends.py (renamed from tests/test_json.py)24
11 files changed, 89 insertions, 46 deletions
diff --git a/module/InitHomeDir.py b/module/InitHomeDir.py
index 156c9f932..ff1e1463b 100644
--- a/module/InitHomeDir.py
+++ b/module/InitHomeDir.py
@@ -63,6 +63,9 @@ if "--configdir=" in args:
configdir = args[pos + 12:].strip()
else:
configdir = args[pos + 12:end].strip()
+elif "nosetests" in args or "nosetests2" in args:
+ configdir = join(pypath, "tests", "config")
+
elif path.exists(path.join(pypath, "module", "config", "configdir")):
f = open(path.join(pypath, "module", "config", "configdir"), "rb")
c = f.read().strip()
diff --git a/pyLoadCore.py b/pyLoadCore.py
index 233eda335..cfb2c38d0 100755
--- a/pyLoadCore.py
+++ b/pyLoadCore.py
@@ -62,7 +62,10 @@ from module.utils.fs import free_space, exists, makedirs, join
from codecs import getwriter
-enc = get_console_encoding(sys.stdout.encoding)
+# test runner overwrites sys.stdout
+if hasattr(sys.stdout, "encoding"): enc = get_console_encoding(sys.stdout.encoding)
+else: enc = "utf8"
+
sys._stdout = sys.stdout
sys.stdout = getwriter(enc)(sys.stdout, errors="replace")
@@ -265,7 +268,7 @@ class Core(object):
print join(path, f)
remove(join(path, f))
- def start(self, rpc=True, web=True):
+ def start(self, rpc=True, web=True, tests=False):
""" starts the fun :D """
self.version = CURRENT_VERSION
@@ -398,6 +401,9 @@ class Core(object):
self.js = JsEngine()
+ # enough initialization for test cases
+ if tests: return
+
self.log.info(_("Downloadtime: %s") % self.api.isTimeDownload())
if rpc:
diff --git a/tests/CrypterPluginTester.py b/tests/CrypterPluginTester.py
index 27013ede7..ceb58adc5 100644
--- a/tests/CrypterPluginTester.py
+++ b/tests/CrypterPluginTester.py
@@ -12,10 +12,10 @@ from module.plugins.Base import Fail
from module.utils import accumulate, to_int
class CrypterPluginTester(PluginTester):
-
@nottest
def test_plugin(self, name, url, flag):
+ print "%s: %s" % (name, url)
log(DEBUG, "%s: %s", name, url)
plugin = self.core.pluginManager.getPluginClass(name)
@@ -57,9 +57,15 @@ h, crypter = c.pluginManager.parseUrls(urls)
plugins = accumulate(crypter)
for plugin, urls in plugins.iteritems():
- for i, url in enumerate(urls):
+ def meta_class(plugin):
+ class _testerClass(CrypterPluginTester):
+ pass
+ _testerClass.__name__ = plugin
+ return _testerClass
+ _testerClass = meta_class(plugin)
+ for i, url in enumerate(urls):
def meta(plugin, url, flag, sig):
def _test(self):
self.test_plugin(plugin, url, flag)
@@ -67,5 +73,9 @@ for plugin, urls in plugins.iteritems():
_test.func_name = sig
return _test
- sig = "test_%s_LINK%d" % (plugin, i)
- setattr(CrypterPluginTester, sig, meta(plugin, url, flags.get(url, None), sig)) \ No newline at end of file
+ sig = "test_LINK%d" % i
+ setattr(_testerClass, sig, meta(plugin, url, flags.get(url, None), sig))
+ print url
+
+ locals()[plugin] = _testerClass
+ del _testerClass \ No newline at end of file
diff --git a/tests/HosterPluginTester.py b/tests/HosterPluginTester.py
index 32b67d93e..bc802ec18 100644
--- a/tests/HosterPluginTester.py
+++ b/tests/HosterPluginTester.py
@@ -1,5 +1,7 @@
# -*- coding: utf-8 -*-
+import __main__
+
from os import remove
from os.path import dirname
from logging import log, DEBUG
@@ -19,7 +21,6 @@ from module.utils.fs import save_join, join, exists
DL_DIR = join("Downloads", "tmp")
class HosterPluginTester(PluginTester):
-
files = {}
def setUp(self):
@@ -31,7 +32,6 @@ class HosterPluginTester(PluginTester):
@nottest
def test_plugin(self, name, url, flag):
-
# Print to stdout to see whats going on
print "%s: %s, %s" % (name, url, flag)
log(DEBUG, "%s: %s, %s", name, url, flag)
@@ -47,13 +47,12 @@ class HosterPluginTester(PluginTester):
a = time()
pyfile.plugin.preprocessing(self.thread)
- log(DEBUG, "downloading took %ds" % (time()-a))
+ log(DEBUG, "downloading took %ds" % (time() - a))
log(DEBUG, "size %d kb" % (pyfile.size / 1024))
if flag == "offline":
raise Exception("No offline Exception raised.")
-
if pyfile.name not in self.files:
raise Exception("Filename %s not recognized." % pyfile.name)
@@ -103,26 +102,38 @@ for l in links:
name, hash = l.rsplit(" ", 1)
HosterPluginTester.files[name] = hash
-
hoster, c = c.pluginManager.parseUrls(urls)
plugins = accumulate(hoster)
for plugin, urls in plugins.iteritems():
+ # closure functions to retain local scope
+ def meta_class(plugin):
+ class _testerClass(HosterPluginTester):
+ pass
+ _testerClass.__name__ = plugin
+ return _testerClass
- for i, url in enumerate(urls):
+ _testerClass = meta_class(plugin)
- def meta(plugin, url, flag, sig):
+ for i, url in enumerate(urls):
+ def meta(__plugin, url, flag, sig):
def _test(self):
- self.test_plugin(plugin, url, flag)
+ self.test_plugin(__plugin, url, flag)
_test.func_name = sig
return _test
tmp_flag = flags.get(url, None)
if flags.get(url, None):
- sig = "test_%s_LINK%d_%s" % (plugin, i, tmp_flag)
+ sig = "test_LINK%d_%s" % (i, tmp_flag)
else:
- sig = "test_%s_LINK%d" % (plugin, i)
+ sig = "test_LINK%d" % i
+
+ # set test method
+ setattr(_testerClass, sig, meta(plugin, url, tmp_flag, sig))
- setattr(HosterPluginTester, sig, meta(plugin, url, flags.get(url, None), sig)) \ No newline at end of file
+ #register class
+ locals()[plugin] = _testerClass
+ # remove from locals, or tested twice
+ del _testerClass \ No newline at end of file
diff --git a/tests/helper/PluginTester.py b/tests/helper/PluginTester.py
index db01a2d06..b70c0d061 100644
--- a/tests/helper/PluginTester.py
+++ b/tests/helper/PluginTester.py
@@ -128,14 +128,14 @@ class PluginTester(TestCase):
@classmethod
def setUpClass(cls):
cls.core = Core()
- name = "%s.%s" % (cls.__name__, cls.__name__)
+ name = "%s.%s" % (cls.__module__, cls.__name__)
for f in glob(join(name, "debug_*")):
remove(f)
# Copy debug report to attachment dir for jenkins
@classmethod
def tearDownClass(cls):
- name = "%s.%s" % (cls.__name__, cls.__name__)
+ name = "%s.%s" % (cls.__module__, cls.__name__)
if not exists(name): makedirs(name)
for f in glob("debug_*"):
move(f, join(name, f))
diff --git a/tests/helper/Stubs.py b/tests/helper/Stubs.py
index eb3cc98c1..cfa5d6fdb 100644
--- a/tests/helper/Stubs.py
+++ b/tests/helper/Stubs.py
@@ -66,7 +66,7 @@ class Core:
self.requestFactory = RequestFactory(self)
__builtin__.pyreq = self.requestFactory
self.accountManager = AccountManager()
- self.hookManager = self.eventManager = self.interActionManager = NopClass()
+ self.hookManager = self.eventManager = self.interActionManager = NoopClass()
self.js = JsEngine()
self.cache = {}
self.packageCache = {}
@@ -89,8 +89,7 @@ class Core:
return PyPackage(self, 0, "tmp", "tmp", "", "", 0, 0)
-
-class NopClass:
+class NoopClass:
def __getattr__(self, item):
return noop
@@ -114,6 +113,6 @@ class Thread(BaseThread):
return dump
__builtin__._ = lambda x: x
-__builtin__.pypath = ""
-__builtin__.hookManager = NopClass()
+__builtin__.pypath = abspath(join(dirname(__file__), "..", ".."))
+__builtin__.hookManager = NoopClass()
__builtin__.pyreq = None \ No newline at end of file
diff --git a/tests/hosterlinks.txt b/tests/hosterlinks.txt
index 00a68eb03..f255661ab 100755
--- a/tests/hosterlinks.txt
+++ b/tests/hosterlinks.txt
@@ -2,7 +2,7 @@
# Valid files, with md5 hash
# Please only use files around 5-15 MB
-# http://download.pyload.org/random.bin
+http://download.pyload.org/random.bin
random.bin d76505d0869f9f928a17d42d66326307
Mořská želva ( Зелёная черепаха .&+ 綠蠵龜 _@- Đồi mồi dứa ).tar 932212256dc0b0a1e71c0944eef633a4
@@ -43,6 +43,6 @@ http://www.fshare.vn/file/A7H8LSTP7Z/
http://ifile.it/muwgivz
http://letitbit.net/download/67793.60a7d3745791db7271a6e6c92cfe/Mořská_želva_(_Зелёная_черепаха_.___綠蠵龜___-_Đồi_mồi_dứa_).tar.html
http://www.mediafire.com/?n09th58z1x5r585
-http://www.quickshare.cz/stahnout-soubor/676150:morska-zelva----_-oi-moi-dua-tar_6MB
+http://www.quickshare.cz/stahnout-soubor/676150:morska-zelva----_-oi-moi-dua-tar_6MB
http://www.uloz.to/12553820/morska-zelva-oi-moi-dua-tar
http://www.wupload.com/file/2642593407/ \ No newline at end of file
diff --git a/tests/plugin_tests.sh b/tests/plugin_tests.sh
index a0260b5bb..be06c0dc5 100755
--- a/tests/plugin_tests.sh
+++ b/tests/plugin_tests.sh
@@ -1,5 +1,7 @@
#!/usr/bin/env bash
NS=nosetests
which nosetests2 > /dev/null && NS=nosetests2
-$NS tests/HosterPluginTester.py tests/CrypterPluginTester.py -s --with-xunit --with-coverage --cover-erase --cover-package=module.plugins
+# must be executed within tests dir
+cd "$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
+$NS HosterPluginTester.py CrypterPluginTester.py -s --with-xunit --with-coverage --cover-erase --cover-package=module.plugins --with-id
coverage xml
diff --git a/tests/sloccount.sh b/tests/sloccount.sh
index 70150501e..cd9eacaa4 100755
--- a/tests/sloccount.sh
+++ b/tests/sloccount.sh
@@ -1,2 +1,2 @@
#!/bin/bash
-sloccount --duplicates --wide --details . > sloccount.sc
+sloccount --duplicates --wide --details module pyLoadCore.py pyLoadCli.py > sloccount.sc
diff --git a/tests/test_api.py b/tests/test_api.py
index 76b3e1b40..236f72882 100644
--- a/tests/test_api.py
+++ b/tests/test_api.py
@@ -1,18 +1,18 @@
-# -*- coding: utf-8 -*-
-from module.common import APIExerciser
-from nose.tools import nottest
+from unittest import TestCase
+from pyLoadCore import Core
+from module.common.APIExerciser import APIExerciser
-class TestApi:
+class TestApi(TestCase):
- def __init__(self):
- self.api = APIExerciser.APIExerciser(None, True, "TestUser", "sometestpw")
+ @classmethod
+ def setUpClass(cls):
+ cls.core = Core()
+ cls.core.start(False, False, True)
- def test_login(self):
- assert self.api.api.login("crapp", "wrong pw") is False
-
- #@nottest
def test_random(self):
- for i in range(0, 1000):
- self.api.testAPI()
+ api = APIExerciser(self.core)
+
+ for i in range(2000):
+ api.testAPI() \ No newline at end of file
diff --git a/tests/test_json.py b/tests/test_backends.py
index 4e8fb0e1f..71ccedd2f 100644
--- a/tests/test_json.py
+++ b/tests/test_backends.py
@@ -1,13 +1,30 @@
# -*- coding: utf-8 -*-
+
from urllib import urlencode
from urllib2 import urlopen, HTTPError
from json import loads
from logging import log
+
+from module.common import APIExerciser
+
url = "http://localhost:8001/api/%s"
-class TestJson:
+class TestBackends():
+
+ def setUp(self):
+ u = urlopen(url % "login", data=urlencode({"username": "TestUser", "password": "sometestpw"}))
+ self.key = loads(u.read())
+ assert self.key is not False
+
+ def test_random(self):
+ api = APIExerciser.APIExerciser(None, True, "TestUser", "sometestpw")
+
+ assert api.api.login("crapp", "wrong pw") is False
+
+ for i in range(0, 1000):
+ api.testAPI()
def call(self, name, post=None):
if not post: post = {}
@@ -15,11 +32,6 @@ class TestJson:
u = urlopen(url % name, data=urlencode(post))
return loads(u.read())
- def setUp(self):
- u = urlopen(url % "login", data=urlencode({"username": "TestUser", "password": "sometestpw"}))
- self.key = loads(u.read())
- assert self.key is not False
-
def test_wronglogin(self):
u = urlopen(url % "login", data=urlencode({"username": "crap", "password": "wrongpw"}))
assert loads(u.read()) is False