-
Notifications
You must be signed in to change notification settings - Fork 0
/
phennytest.py
74 lines (67 loc) · 1.79 KB
/
phennytest.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
"""
stuff for testing Phenny modules
example:
if __name__ == '__main__':
import sys
sys.path.extend(('.','..')) # so we can find phennytest
from phennytest import PhennyFake, CommandInputFake
PHENNYFAKE = PhennyFake()
CMDFAKE = CommandInputFake('.wub a dub dub')
wub(PHENNYFAKE, CMDFAKE)
"""
import sys, re
class ConfigFake():
" fakes the module created by importing ~/.phenny/phenny.conf "
def __init__(self):
self.nick = 'botnick'
self.name = 'Phenny Palmersbot,'
self.channels = ['#test']
self.password = None
self.owner = 'botowner'
self.admins = [self.owner, 'botadmin']
self.prefix = r'\.'
class PhennyFake(object):
" use in place of PhennyWrapped "
@staticmethod
def say(mmm):
print mmm
@staticmethod
def reply(mmm):
PhennyFake.say("nick: "+mmm)
@staticmethod
def write(args, trailing=None):
mesg = ': '+' '.join(args)
if trailing:
mesg += ' :'+trailing
print mesg
@staticmethod
def msg(destination, text):
PhennyFake.write(('PRIVMSG', destination), text)
@staticmethod
def log(mesg):
sys.stderr.write(mesg)
def __init__(self, config=None):
if not config:
config = ConfigFake()
if not hasattr(config,'prefix') or not config.prefix :
config.prefix = r'\.'
self.config = config
self.doc = {}
self.stats = {}
self.variables = {}
self.stack = list()
class CommandInputFake(unicode):
" use in place of CommandInput "
def __new__(cls, text):
cmd_re = r'^[\.\!](\S+)(?: +(.*))?$'
cif = unicode.__new__(cls, text)
cif.sender = '#test'
cif.nick = 'self'
cif.admin = False
cif.event = 'PRIVMSG'
cif.bytes = ':'+text
cif.match = re.match(cmd_re, text)
cif.groups = cif.match.groups
cif.group = cif.match.group
cif.args = ()
return cif