Revision 27058e48 kamaki/clients/connection/test.py
b/kamaki/clients/connection/test.py | ||
---|---|---|
31 | 31 |
# interpreted as representing official policies, either expressed |
32 | 32 |
# or implied, of GRNET S.A. |
33 | 33 |
|
34 |
from unittest import TestCase, TestSuite, makeSuite, TextTestRunner
|
|
34 |
from unittest import TestCase |
|
35 | 35 |
from mock import Mock, patch, call |
36 | 36 |
from random import randrange |
37 | 37 |
from urllib2 import quote |
... | ... | |
362 | 362 |
self.assertTrue(isinstance(r, str)) |
363 | 363 |
|
364 | 364 |
|
365 |
def get_test_classes(module=__import__(__name__), name=''): |
|
366 |
from inspect import getmembers, isclass |
|
367 |
for objname, obj in getmembers(module): |
|
368 |
if (objname == name or not name) and isclass(obj) and ( |
|
369 |
issubclass(obj, TestCase)): |
|
370 |
yield (obj, objname) |
|
371 |
|
|
372 |
|
|
373 |
def main(argv): |
|
374 |
for cls, name in get_test_classes(name=argv[1] if len(argv) > 1 else ''): |
|
375 |
args = argv[2:] |
|
376 |
suite = TestSuite() |
|
377 |
if args: |
|
378 |
suite.addTest(cls('_'.join(['test'] + args))) |
|
379 |
else: |
|
380 |
suite.addTest(makeSuite(cls)) |
|
381 |
print('Test %s' % name) |
|
382 |
TextTestRunner(verbosity=2).run(suite) |
|
383 |
|
|
384 |
|
|
385 | 365 |
if __name__ == '__main__': |
386 | 366 |
from sys import argv |
387 |
main(argv) |
|
367 |
from kamaki.clients.test import runTestCase |
|
368 |
classes = dict( |
|
369 |
KamakiConnection=KamakiConnection, |
|
370 |
KamakiHTTPConnection=KamakiHTTPConnection, |
|
371 |
KamakiHTTPResponse=KamakiHTTPResponse, |
|
372 |
KamakiResponse=KamakiResponse) |
|
373 |
not_found = True |
|
374 |
for k, cls in classes.items(): |
|
375 |
if not argv[1:] or argv[1] == k: |
|
376 |
not_found = False |
|
377 |
runTestCase(cls, '%s Client' % k, argv[2:]) |
|
378 |
if not_found: |
|
379 |
print('TestCase %s not found' % argv[1]) |
Also available in: Unified diff