supybot-test: Add a new level of verbosity, for showing only unexpected exceptions.

This commit is contained in:
Valentin Lorentz 2015-08-29 23:02:20 +02:00
parent e5d8315e64
commit 09cb8e977f
3 changed files with 31 additions and 16 deletions

View File

@ -52,6 +52,7 @@ supybot.directories.conf: test-conf
supybot.directories.log: test-logs supybot.directories.log: test-logs
supybot.reply.whenNotCommand: True supybot.reply.whenNotCommand: True
supybot.log.stdout: False supybot.log.stdout: False
supybot.log.stdout.level: ERROR
supybot.log.level: DEBUG supybot.log.level: DEBUG
supybot.log.format: %(levelname)s %(message)s supybot.log.format: %(levelname)s %(message)s
supybot.log.plugins.individualLogfiles: False supybot.log.plugins.individualLogfiles: False
@ -129,8 +130,8 @@ if __name__ == '__main__':
dest='timeout', dest='timeout',
help='Sets the timeout, in seconds, for tests to return ' help='Sets the timeout, in seconds, for tests to return '
'responses.') 'responses.')
parser.add_option('-v', '--verbose', action='store_true', default=False, parser.add_option('-v', '--verbose', action='count', default=0,
help='Sets the verbose flag, logging extra information ' help='Increase verbosity, logging extra information '
'about each test that runs.') 'about each test that runs.')
parser.add_option('', '--no-network', action='store_true', default=False, parser.add_option('', '--no-network', action='store_true', default=False,
dest='nonetwork', help='Causes the network-based tests ' dest='nonetwork', help='Causes the network-based tests '
@ -150,6 +151,9 @@ if __name__ == '__main__':
parser.add_option('', '--disable-multiprocessing', action='store_true', parser.add_option('', '--disable-multiprocessing', action='store_true',
dest='disableMultiprocessing', dest='disableMultiprocessing',
help='Disables multiprocessing stuff.') help='Disables multiprocessing stuff.')
parser.add_option('', '--verbose-unexcepted-errors', action='store_true',
dest='verboseUnexceptectedErros',
help='Show the full traceback of unexpected errors.')
(options, args) = parser.parse_args() (options, args) = parser.parse_args()
world.disableMultiprocessing = options.disableMultiprocessing world.disableMultiprocessing = options.disableMultiprocessing
@ -177,10 +181,7 @@ if __name__ == '__main__':
atexit.register(fd.close) atexit.register(fd.close)
atexit.register(lambda : sys.settrace(None)) atexit.register(lambda : sys.settrace(None))
if options.verbose: world.myVerbose = options.verbose
world.myVerbose = True
else:
world.myVerbose = False
if options.nonetwork: if options.nonetwork:
test.network = False test.network = False

View File

@ -52,6 +52,11 @@ else:
from urllib.parse import splithost, splituser from urllib.parse import splithost, splituser
from urllib.request import URLopener from urllib.request import URLopener
class verbosity:
NONE = 0
EXCEPTIONS = 1
MESSAGES = 2
i18n.import_conf() i18n.import_conf()
network = True network = True
@ -262,14 +267,14 @@ class PluginTestCase(SupyTestCase):
gc.collect() gc.collect()
def _feedMsg(self, query, timeout=None, to=None, frm=None, def _feedMsg(self, query, timeout=None, to=None, frm=None,
usePrefixChar=True): usePrefixChar=True, expectException=False):
if to is None: if to is None:
to = self.irc.nick to = self.irc.nick
if frm is None: if frm is None:
frm = self.prefix frm = self.prefix
if timeout is None: if timeout is None:
timeout = self.timeout timeout = self.timeout
if self.myVerbose: if self.myVerbose >= verbosity.MESSAGES:
print('') # Extra newline, so it's pretty. print('') # Extra newline, so it's pretty.
prefixChars = conf.supybot.reply.whenAddressedBy.chars() prefixChars = conf.supybot.reply.whenAddressedBy.chars()
if not usePrefixChar and query[0] in prefixChars: if not usePrefixChar and query[0] in prefixChars:
@ -277,8 +282,10 @@ class PluginTestCase(SupyTestCase):
if minisix.PY2: if minisix.PY2:
query = query.encode('utf8') # unicode->str query = query.encode('utf8') # unicode->str
msg = ircmsgs.privmsg(to, query, prefix=frm) msg = ircmsgs.privmsg(to, query, prefix=frm)
if self.myVerbose: if self.myVerbose >= verbosity.MESSAGES:
print('Feeding: %r' % msg) print('Feeding: %r' % msg)
if not expectException and self.myVerbose >= verbosity.EXCEPTIONS:
conf.supybot.log.stdout.setValue(True)
self.irc.feedMsg(msg) self.irc.feedMsg(msg)
fed = time.time() fed = time.time()
response = self.irc.takeMsg() response = self.irc.takeMsg()
@ -286,8 +293,10 @@ class PluginTestCase(SupyTestCase):
time.sleep(0.1) # So it doesn't suck up 100% cpu. time.sleep(0.1) # So it doesn't suck up 100% cpu.
drivers.run() drivers.run()
response = self.irc.takeMsg() response = self.irc.takeMsg()
if self.myVerbose: if self.myVerbose >= verbosity.MESSAGES:
print('Response: %r' % response) print('Response: %r' % response)
if not expectException and self.myVerbose >= verbosity.EXCEPTIONS:
conf.supybot.log.stdout.setValue(False)
return response return response
def getMsg(self, query, **kwargs): def getMsg(self, query, **kwargs):
@ -306,7 +315,7 @@ class PluginTestCase(SupyTestCase):
# But that would be hard, so I don't bother. When this breaks, it'll get # But that would be hard, so I don't bother. When this breaks, it'll get
# fixed, but not until then. # fixed, but not until then.
def assertError(self, query, **kwargs): def assertError(self, query, **kwargs):
m = self._feedMsg(query, **kwargs) m = self._feedMsg(query, expectException=True, **kwargs)
if m is None: if m is None:
raise TimeoutError(query) raise TimeoutError(query)
if lastGetHelp not in m.args[1]: if lastGetHelp not in m.args[1]:
@ -454,7 +463,7 @@ class ChannelPluginTestCase(PluginTestCase):
self.assertEqual(m.command, 'WHO') self.assertEqual(m.command, 'WHO')
def _feedMsg(self, query, timeout=None, to=None, frm=None, private=False, def _feedMsg(self, query, timeout=None, to=None, frm=None, private=False,
usePrefixChar=True): usePrefixChar=True, expectException=False):
if to is None: if to is None:
if private: if private:
to = self.irc.nick to = self.irc.nick
@ -464,15 +473,17 @@ class ChannelPluginTestCase(PluginTestCase):
frm = self.prefix frm = self.prefix
if timeout is None: if timeout is None:
timeout = self.timeout timeout = self.timeout
if self.myVerbose: if self.myVerbose >= verbosity.MESSAGES:
print('') # Newline, just like PluginTestCase. print('') # Newline, just like PluginTestCase.
prefixChars = conf.supybot.reply.whenAddressedBy.chars() prefixChars = conf.supybot.reply.whenAddressedBy.chars()
if query[0] not in prefixChars and usePrefixChar: if query[0] not in prefixChars and usePrefixChar:
query = prefixChars[0] + query query = prefixChars[0] + query
if minisix.PY2 and isinstance(query, unicode): if minisix.PY2 and isinstance(query, unicode):
query = query.encode('utf8') # unicode->str query = query.encode('utf8') # unicode->str
if not expectException and self.myVerbose >= verbosity.EXCEPTIONS:
conf.supybot.log.stdout.setValue(True)
msg = ircmsgs.privmsg(to, query, prefix=frm) msg = ircmsgs.privmsg(to, query, prefix=frm)
if self.myVerbose: if self.myVerbose >= verbosity.MESSAGES:
print('Feeding: %r' % msg) print('Feeding: %r' % msg)
self.irc.feedMsg(msg) self.irc.feedMsg(msg)
fed = time.time() fed = time.time()
@ -497,8 +508,10 @@ class ChannelPluginTestCase(PluginTestCase):
ret = response ret = response
else: else:
ret = None ret = None
if self.myVerbose: if self.myVerbose >= verbosity.MESSAGES:
print('Returning: %r' % ret) print('Returning: %r' % ret)
if not expectException and self.myVerbose >= verbosity.EXCEPTIONS:
conf.supybot.log.stdout.setValue(False)
return ret return ret
def feedMsg(self, query, to=None, frm=None, private=False): def feedMsg(self, query, to=None, frm=None, private=False):

View File

@ -527,7 +527,8 @@ class PrivmsgTestCase(ChannelPluginTestCase):
original = str(conf.supybot.reply.whenNotCommand) original = str(conf.supybot.reply.whenNotCommand)
conf.supybot.reply.whenNotCommand.set('True') conf.supybot.reply.whenNotCommand.set('True')
self.irc.addCallback(self.BadInvalidCommand(self.irc)) self.irc.addCallback(self.BadInvalidCommand(self.irc))
self.assertRegexp('asdfjkl', 'not a valid command') self.assertRegexp('asdfjkl', 'not a valid command',
expectException=True)
finally: finally:
conf.supybot.reply.whenNotCommand.set(original) conf.supybot.reply.whenNotCommand.set(original)