aboutsummaryrefslogtreecommitdiffstats
path: root/local
diff options
context:
space:
mode:
authorkongr45gpen <electrovesta@gmail.com>2014-04-28 19:07:21 +0300
committerkongr45gpen <electrovesta@gmail.com>2014-04-28 19:07:21 +0300
commit4665d27418eb4a426f6ff52352285d6430ba0841 (patch)
tree30901457e418f1f2e4c866f32f13782a31a14273 /local
parentac155dc4e25a6c91d36d9c7b5f8bed9aacbb426c (diff)
downloadsupybot_github-4665d27418eb4a426f6ff52352285d6430ba0841.tar.gz
supybot_github-4665d27418eb4a426f6ff52352285d6430ba0841.tar.bz2
supybot_github-4665d27418eb4a426f6ff52352285d6430ba0841.zip
Make tests look Rubyish
Diffstat (limited to 'local')
-rw-r--r--local/handler/GithubHandler.py10
-rw-r--r--local/handler/IssueCommentHandler.py2
-rw-r--r--local/handler/IssueHandler.py2
-rw-r--r--local/handler/PushHandler.py2
-rw-r--r--local/handler/StatusHandler.py2
-rw-r--r--local/handler/WikiHandler.py2
-rw-r--r--local/testing/ExpectationPluginTestCase.py115
-rw-r--r--local/testing/__init__.py0
-rw-r--r--local/utility.py6
9 files changed, 131 insertions, 10 deletions
diff --git a/local/handler/GithubHandler.py b/local/handler/GithubHandler.py
index 6735f22..788ef94 100644
--- a/local/handler/GithubHandler.py
+++ b/local/handler/GithubHandler.py
@@ -90,16 +90,16 @@ class GithubHandler(BaseHTTPServer.BaseHTTPRequestHandler):
msgs = []
if 'pages' in data:
- msgs = WikiHandler.handle(irc, data)
+ msgs = WikiHandler.handle(data)
elif 'state' in data:
- msgs = StatusHandler.handle(irc, data)
+ msgs = StatusHandler.handle(data)
elif 'commits' in data:
- msgs = PushHandler.handle(irc, data)
+ msgs = PushHandler.handle(data)
elif 'issue' in data:
if 'comment' in data:
- msgs = IssueCommentHandler.handle(irc, data)
+ msgs = IssueCommentHandler.handle(data)
else:
- msgs = IssueHandler.handle(irc, data)
+ msgs = IssueHandler.handle(data)
else:
msgs.append( ircmsgs.privmsg(channel, "Something happened"))
diff --git a/local/handler/IssueCommentHandler.py b/local/handler/IssueCommentHandler.py
index b5f70c0..ba6d846 100644
--- a/local/handler/IssueCommentHandler.py
+++ b/local/handler/IssueCommentHandler.py
@@ -1,6 +1,6 @@
from ..utility import *
-def handle(irc, data):
+def handle(data):
msgs = []
url = getShortURL(data['comment']['html_url'])
diff --git a/local/handler/IssueHandler.py b/local/handler/IssueHandler.py
index 642b042..1ae9a6d 100644
--- a/local/handler/IssueHandler.py
+++ b/local/handler/IssueHandler.py
@@ -1,6 +1,6 @@
from ..utility import *
-def handle(irc, data):
+def handle(data):
msgs = []
url = data['issue']['url']
diff --git a/local/handler/PushHandler.py b/local/handler/PushHandler.py
index 4ec927b..12c9455 100644
--- a/local/handler/PushHandler.py
+++ b/local/handler/PushHandler.py
@@ -1,6 +1,6 @@
from ..utility import *
-def handle(irc, data):
+def handle(data):
msgs = []
commitno = len(data['commits'])
diff --git a/local/handler/StatusHandler.py b/local/handler/StatusHandler.py
index 270e9f3..46e2e67 100644
--- a/local/handler/StatusHandler.py
+++ b/local/handler/StatusHandler.py
@@ -1,6 +1,6 @@
from ..utility import *
-def handle(irc, data):
+def handle(data):
msgs = []
msgs.append( "%s: %s - %s (%s)" % (
diff --git a/local/handler/WikiHandler.py b/local/handler/WikiHandler.py
index 8739159..8ea3b70 100644
--- a/local/handler/WikiHandler.py
+++ b/local/handler/WikiHandler.py
@@ -1,6 +1,6 @@
from ..utility import *
-def handle(irc, data):
+def handle(data):
msgs = []
pageno = len(data['pages'])
diff --git a/local/testing/ExpectationPluginTestCase.py b/local/testing/ExpectationPluginTestCase.py
new file mode 100644
index 0000000..af6e56d
--- /dev/null
+++ b/local/testing/ExpectationPluginTestCase.py
@@ -0,0 +1,115 @@
+###
+from supybot.log import info
+from supybot.test import *
+
+from sys import stdout
+from time import sleep
+
+import re
+import urllib
+
+from ..utility import clean
+
+class ExpectationPluginTestCase(PluginTestCase):
+ plugins = {}
+
+ def describe(self, query, *args):
+ m = self._feedMsg('get ' + query)
+ manyEs = tcolors.FAIL + 'E' * len(args) + tcolors.ENDC
+ if m is None:
+ print manyEs
+ raise TimeoutError, query
+ if m.args[1].startswith('Error:'):
+ print manyEs
+ self.fail('%r errored: %s' % (query, m.args[1]))
+
+ errors = []
+ for expectation in args:
+ expectation.reply = m.args[1]
+ if expectation.evaluate():
+ stdout.write(tcolors.OKGREEN + '.' + tcolors.ENDC)
+ else:
+ stdout.write(tcolors.FAIL + 'F' + tcolors.ENDC)
+ errors.append(expectation.getSummary())
+ stdout.flush()
+ stdout.write('')
+ stdout.flush()
+
+ if errors:
+ print "\n%sWhile describing %s" % (tcolors.FAIL, query)
+ for error in errors:
+ print "- Failed to assert that %s" % (error,)
+ print tcolors.ENDC
+ self.fail()
+
+ def sendRequest(self, file):
+ """ Opens the `samples` folder and sends a file as a request
+ to the plugin's server """
+ if file in self.files:
+ content = self.files[file]
+ else:
+ with open('samples/' + file + '.json', 'r') as content_file:
+ content = content_file.read()
+ self.files[file] = content
+ res = urllib.urlopen('http://localhost:' + str(self.port), 'payload=' + content)
+
+ def testDocumentation(self):
+ if self.__class__ == ExpectationPluginTestCase:
+ return
+ else:
+ PluginTestCase.testDocumentation(self)
+
+ def setUp(self):
+ # Prevent supybot's testDocumentation from going mad
+ PluginTestCase.setUp(self)
+
+ def tearDown(self):
+ # Add a space between our LEDs and python's OK message
+ PluginTestCase.tearDown(self)
+ stdout.write(' ')
+ stdout.flush()
+
+class tcolors:
+ HEADER = '\033[95m'
+ OKBLUE = '\033[94m'
+ OKGREEN = '\033[92m'
+ WARNING = '\033[93m'
+ FAIL = '\033[91m'
+ ENDC = '\033[0m'
+
+def expect(query):
+ m = GithubTestCase._feedMsg('get' + query)
+ return Expectation(m.args[1])
+
+def it():
+ return Expectation()
+
+class Expectation:
+ def __init__(self):
+ self.error = ''
+ self.should = self
+ self.to = self
+
+ def evaluate(self):
+ return self.assertion()
+
+ def cleanReply(self):
+ return clean(self.reply)
+
+ def getSummary(self):
+ if self.assertionParameter:
+ return self.summary % (self.cleanReply(), self.assertionParameter)
+ else:
+ return self.summary % (self.cleanReply())
+
+ def contain(self, what):
+ self.assertion = self.contains
+ self.assertionParameter = what
+ self.summary = "'%s' contains '%s'"
+ return self
+
+ def contains(self, flags=re.I):
+ return re.search(self.assertionParameter, self.cleanReply(), flags)
+
+class Object(object):
+ pass
diff --git a/local/testing/__init__.py b/local/testing/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/local/testing/__init__.py
diff --git a/local/utility.py b/local/utility.py
index 2640e41..2ae1491 100644
--- a/local/utility.py
+++ b/local/utility.py
@@ -1,3 +1,4 @@
+import re
import urllib2
import supybot.conf as conf
@@ -71,6 +72,11 @@ def saveMessages(msgs):
return
globals.messageList = msgs
+def clean(string):
+ """Strips IRC control characters from a string"""
+ regex = re.compile("((\x02)|(\x03))(?:\d{1,2}(?:,\d{1,2})?)?", re.UNICODE)
+ return regex.sub('', string)
+
# Possible colours:
# white, black, (light/dark) blue, (light) green, red, brown, purple,
# orange, yellow, teal, pink, light/dark gray/grey

© 2014-2024 Faster IT GmbH | imprint | privacy policy