Skip to content

Commit

Permalink
Add test runner, localized test command and tests for it
Browse files Browse the repository at this point in the history
  • Loading branch information
kxepal committed Jan 5, 2014
1 parent 36e8252 commit 8fecd36
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 3 deletions.
6 changes: 3 additions & 3 deletions tasman/app.py
Expand Up @@ -12,6 +12,6 @@
app = XmppFlask('tasman')


@app.route(u'test')
def test():
return 'passed'
@app.route(u'<any(test,тест):msg>')
def test(msg):
return 'passed' if msg == 'test' else u'пассед'
27 changes: 27 additions & 0 deletions tasman/tests/__init__.py
Expand Up @@ -6,3 +6,30 @@
# This software is licensed as described in the file LICENSE, which
# you should have received as part of this distribution.
#

import os.path
import unittest


def main():
suite = unittest.TestSuite()
for root, dirs, files in os.walk('.'):
for file in files:
if not (file.startswith('test_') and file.endswith('.py')):
continue
name = file.split('.')[0]
modname = os.path.join(root, name).replace(os.path.sep, '.')
modname = modname.lstrip('.')
try:
tests = unittest.defaultTestLoader.loadTestsFromName(modname)
except Exception, err:
print modname, ':', type(err), err
else:
for test in tests:
suite.addTests(test)
print modname, ':', tests.countTestCases(), 'tests'
return suite


if __name__ == '__main__':
unittest.main(defaultTest='main')
32 changes: 32 additions & 0 deletions tasman/tests/test_cmd_test.py
@@ -0,0 +1,32 @@
# -*- coding: utf-8 -*-
#
# Copyright (C) 2014 Alexander Shorin
# All rights reserved.
#
# This software is licensed as described in the file LICENSE, which
# you should have received as part of this distribution.
#

import unittest
from tasman.app import app


class TestCmdTestCase(unittest.TestCase):

def test_passed(self):
environ = {'MESSAGE': 'test', 'XMPP_JID': 'k.bx@ya.ru'}

rv = app(environ)
self.assertEquals(list(rv), ['passed'])

def test_passed_ru(self):
environ = {'MESSAGE': u'тест', 'XMPP_JID': 'k.bx@ya.ru'}

rv = app(environ)
self.assertEquals(list(rv), [u'пассед'])

def test_strict(self):
environ = {'MESSAGE': 'test test test', 'XMPP_JID': 'k.bx@ya.ru'}

rv = app(environ)
self.assertEquals(list(rv), [])

0 comments on commit 8fecd36

Please sign in to comment.