diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/HosterPluginTester.py | 71 | ||||
-rw-r--r-- | tests/helper/PluginTester.py | 5 | ||||
-rw-r--r-- | tests/helper/Stubs.py | 11 | ||||
-rw-r--r-- | tests/helper/parser.py | 22 |
4 files changed, 66 insertions, 43 deletions
diff --git a/tests/HosterPluginTester.py b/tests/HosterPluginTester.py index 0639adab7..3a6eca84b 100644 --- a/tests/HosterPluginTester.py +++ b/tests/HosterPluginTester.py @@ -5,20 +5,21 @@ from logging import log, DEBUG from hashlib import md5 from time import time from shutil import move -import codecs from nose.tools import nottest from helper.Stubs import Core +from helper.parser import parse_config from helper.PluginTester import PluginTester -from pyload.datatypes.PyFile import PyFile +from pyload.datatypes.PyFile import PyFile, statusMap from pyload.plugins.Base import Fail from pyload.utils import accumulate from pyload.utils.fs import save_join, join, exists, listdir, remove, stat DL_DIR = join("Downloads", "tmp") + class HosterPluginTester(PluginTester): files = {} @@ -35,13 +36,13 @@ class HosterPluginTester(PluginTester): @nottest - def test_plugin(self, name, url, flag): + def test_plugin(self, name, url, status): # Print to stdout to see whats going on - print "%s: %s, %s" % (name, url.encode("utf8"), flag) - log(DEBUG, "%s: %s, %s", name, url.encode("utf8"), flag) + print "%s: %s, %s" % (name, url.encode("utf8"), status) + log(DEBUG, "%s: %s, %s", name, url.encode("utf8"), status) # url and plugin should be only important thing - pyfile = PyFile(self.core, -1, url, url, 0, 0, "", name, 0, 0) + pyfile = PyFile(self.core, -1, url, url, 0, 0, 0, 0, url, name, "", 0, 0, 0, 0) pyfile.initPlugin() self.thread.pyfile = pyfile @@ -54,7 +55,7 @@ class HosterPluginTester(PluginTester): log(DEBUG, "downloading took %ds" % (time() - a)) log(DEBUG, "size %d kb" % (pyfile.size / 1024)) - if flag == "offline": + if status == "offline": raise Exception("No offline Exception raised.") if pyfile.name not in self.files: @@ -73,7 +74,7 @@ class HosterPluginTester(PluginTester): if hash.hexdigest() != self.files[pyfile.name]: log(DEBUG, "Hash is %s" % hash.hexdigest()) - + size = stat(f.name).st_size if size < 1024 * 1024 * 10: # 10MB # Copy for debug report @@ -82,38 +83,36 @@ class HosterPluginTester(PluginTester): raise Exception("Hash does not match.") - - except Exception, e: - if isinstance(e, Fail) and flag == "fail": + if isinstance(e, Fail) and status == "failed": pass - elif isinstance(e, Fail) and flag == "offline" and e.message == "offline": + elif isinstance(e, Fail) and status == "offline" and e.message == "offline": pass else: raise - # setup methods - c = Core() -# decode everything as unicode -f = codecs.open(join(dirname(__file__), "hosterlinks.txt"), "r", "utf_8") -links = [x.strip() for x in f.readlines()] -urls = [] -flags = {} +sections = parse_config(join(dirname(__file__), "hosterlinks.txt")) -for l in links: - if not l or l.startswith("#"): continue - if l.startswith("http"): - if "||" in l: - l, flag = l.split("||") - flags[l] = str(flag.strip()) - urls.append(l) +for f in sections["files"]: + name, hash = f.rsplit(" ", 1) + HosterPluginTester.files[name] = str(hash) - elif len(l.rsplit(" ", 1)) == 2: - name, hash = l.rsplit(" ", 1) - HosterPluginTester.files[name] = str(hash) +del sections["files"] + +print HosterPluginTester.files + +urls = [] +status = {} + +for k, v in sections.iteritems(): + if k not in statusMap: + print "Unknown status %s" % k + for url in v: + urls.append(url) + status[url] = k hoster, c = c.pluginManager.parseUrls(urls) @@ -123,28 +122,28 @@ for plugin, urls in plugins.iteritems(): def meta_class(plugin): class _testerClass(HosterPluginTester): pass + _testerClass.__name__ = plugin return _testerClass _testerClass = meta_class(plugin) for i, url in enumerate(urls): - def meta(__plugin, url, flag, sig): + def meta(__plugin, url, status, sig): def _test(self): - self.test_plugin(__plugin, url, flag) + self.test_plugin(__plugin, url, status) _test.func_name = sig return _test - tmp_flag = flags.get(url, None) - if flags.get(url, None): - sig = "test_LINK%d_%s" % (i, tmp_flag) + tmp_status = status.get(url) + if tmp_status != "online": + sig = "test_LINK%d_%s" % (i, tmp_status) else: sig = "test_LINK%d" % i # set test method - setattr(_testerClass, sig, meta(plugin, url, tmp_flag, sig)) - + setattr(_testerClass, sig, meta(plugin, url, tmp_status, sig)) #register class locals()[plugin] = _testerClass diff --git a/tests/helper/PluginTester.py b/tests/helper/PluginTester.py index 9312eb7bf..2bfb16af7 100644 --- a/tests/helper/PluginTester.py +++ b/tests/helper/PluginTester.py @@ -16,7 +16,8 @@ from json import loads from Stubs import Thread, Core, noop from pyload.network.RequestFactory import getRequest, getURL -from pyload.plugins.Hoster import Hoster, Abort, Fail +from pyload.plugins.Base import Abort, Fail +from pyload.plugins.Hoster import Hoster def _wait(self): """ waits the time previously set """ @@ -106,8 +107,6 @@ def respond(ticket, value): finally: f.close() - - def invalidCaptcha(self): log(DEBUG, "Captcha invalid") if self.cTask: diff --git a/tests/helper/Stubs.py b/tests/helper/Stubs.py index 2c356ba3e..551778828 100644 --- a/tests/helper/Stubs.py +++ b/tests/helper/Stubs.py @@ -27,8 +27,10 @@ from logging import log, DEBUG, INFO, WARN, ERROR def noop(*args, **kwargs): pass + ConfigParser.save = noop + class LogStub: def debug(self, *args): log(DEBUG, *args) @@ -72,7 +74,7 @@ class Core: self.accountManager = AccountManager() self.addonManager = AddonManager() self.eventManager = self.evm = NoopClass() - self.interActionManager = self.im = NoopClass() + self.interactionManager = self.im = NoopClass() self.js = JsEngine() self.cache = {} self.packageCache = {} @@ -87,7 +89,7 @@ class Core: def path(self, path): return path - def updateLink(self, *args): + def updateFile(self, *args): pass def updatePackage(self, *args): @@ -96,8 +98,8 @@ class Core: def processingIds(self, *args): return [] - def getPackage(self, id): - return PyPackage(self, 0, "tmp", "tmp", "", "", 0, 0) + def getPackage(self, *args): + return PyPackage(self, 0, "tmp", "tmp", -1, 0, "", "", "", 0, "", 0, 0, 0) def print_exc(self): log(ERROR, format_exc()) @@ -132,6 +134,7 @@ class Thread(BaseThread): return dump + __builtin__._ = lambda x: x __builtin__.pypath = abspath(join(dirname(__file__), "..", "..")) __builtin__.addonManager = AddonManager() diff --git a/tests/helper/parser.py b/tests/helper/parser.py new file mode 100644 index 000000000..5031ca7c3 --- /dev/null +++ b/tests/helper/parser.py @@ -0,0 +1,22 @@ + +import codecs + +def parse_config(path): + f = codecs.open(path, "rb", "utf_8") + result = {} + + current_section = None + for line in f.readlines(): + line = line.strip() + if not line or line.startswith("#"): + continue + + if line.startswith("["): + current_section = line.replace("[", "").replace("]", "") + result[current_section] = [] + else: + if not current_section: + raise Exception("Line without section: %s" % line) + result[current_section].append(line) + + return result |