summaryrefslogtreecommitdiffstats
path: root/tests/HosterPluginTester.py
diff options
context:
space:
mode:
authorGravatar RaNaN <Mast3rRaNaN@hotmail.de> 2013-07-20 21:19:14 +0200
committerGravatar RaNaN <Mast3rRaNaN@hotmail.de> 2013-07-20 21:19:14 +0200
commit37e135d40931617e9e135e15cb0e6dad0667b0cb (patch)
tree62aebc280d4137ab8846b6a3b6982c563f8727c0 /tests/HosterPluginTester.py
parentadded missing init file (diff)
downloadpyload-37e135d40931617e9e135e15cb0e6dad0667b0cb.tar.xz
tried to fix hoster tester, removed unneeded files
Diffstat (limited to 'tests/HosterPluginTester.py')
-rw-r--r--tests/HosterPluginTester.py71
1 files changed, 35 insertions, 36 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