From 85898ca43119589cbc7c3e615ce5d0156a6aa9db Mon Sep 17 00:00:00 2001 From: Stavros Sachtouris Date: Tue, 12 Mar 2013 17:59:02 +0200 Subject: [PATCH] Rearange client packages 4 uniformity in testing --- kamaki/clients/{astakos.py => astakos/__init__.py} | 0 .../clients/{test/astakos.py => astakos/test.py} | 5 ++ .../clients/{cyclades.py => cyclades/__init__.py} | 0 .../clients/{test/cyclades.py => cyclades/test.py} | 5 ++ kamaki/clients/{image.py => image/__init__.py} | 0 kamaki/clients/{test/image.py => image/test.py} | 5 ++ kamaki/clients/{pithos.py => pithos/__init__.py} | 0 kamaki/clients/{test/pithos.py => pithos/test.py} | 5 ++ kamaki/clients/{test/__init__.py => test.py} | 69 +++++++++++--------- setup.py | 5 +- 10 files changed, 61 insertions(+), 33 deletions(-) rename kamaki/clients/{astakos.py => astakos/__init__.py} (100%) rename kamaki/clients/{test/astakos.py => astakos/test.py} (96%) rename kamaki/clients/{cyclades.py => cyclades/__init__.py} (100%) rename kamaki/clients/{test/cyclades.py => cyclades/test.py} (99%) rename kamaki/clients/{image.py => image/__init__.py} (100%) rename kamaki/clients/{test/image.py => image/test.py} (98%) rename kamaki/clients/{pithos.py => pithos/__init__.py} (100%) rename kamaki/clients/{test/pithos.py => pithos/test.py} (99%) rename kamaki/clients/{test/__init__.py => test.py} (73%) diff --git a/kamaki/clients/astakos.py b/kamaki/clients/astakos/__init__.py similarity index 100% rename from kamaki/clients/astakos.py rename to kamaki/clients/astakos/__init__.py diff --git a/kamaki/clients/test/astakos.py b/kamaki/clients/astakos/test.py similarity index 96% rename from kamaki/clients/test/astakos.py rename to kamaki/clients/astakos/test.py index 36e50d6..b343c3b 100644 --- a/kamaki/clients/test/astakos.py +++ b/kamaki/clients/astakos/test.py @@ -118,3 +118,8 @@ class Astakos(TestCase): r = self.client.list() self.assertTrue(len(r) == 1) self.assertEqual(r[0]['auth_token'], self.token) + +if __name__ == '__main__': + from sys import argv + from kamaki.clients.test import runTestCase + runTestCase(Astakos, 'AstakosClient', argv[1:]) diff --git a/kamaki/clients/cyclades.py b/kamaki/clients/cyclades/__init__.py similarity index 100% rename from kamaki/clients/cyclades.py rename to kamaki/clients/cyclades/__init__.py diff --git a/kamaki/clients/test/cyclades.py b/kamaki/clients/cyclades/test.py similarity index 99% rename from kamaki/clients/test/cyclades.py rename to kamaki/clients/cyclades/test.py index f71e060..d982a08 100644 --- a/kamaki/clients/test/cyclades.py +++ b/kamaki/clients/cyclades/test.py @@ -636,3 +636,8 @@ class Cyclades(TestCase): self.assertEqual( (img_ref, '/meta/' + key), images_delete.call_args[0]) + +if __name__ == '__main__': + from sys import argv + from kamaki.clients.test import runTestCase + runTestCase(Cyclades, 'Cyclades (multi) Client', argv[1:]) diff --git a/kamaki/clients/image.py b/kamaki/clients/image/__init__.py similarity index 100% rename from kamaki/clients/image.py rename to kamaki/clients/image/__init__.py diff --git a/kamaki/clients/test/image.py b/kamaki/clients/image/test.py similarity index 98% rename from kamaki/clients/test/image.py rename to kamaki/clients/image/test.py index 6de32e9..155938a 100644 --- a/kamaki/clients/test/image.py +++ b/kamaki/clients/image/test.py @@ -323,3 +323,8 @@ class Image(TestCase): '/shared-images/%s' % img0['id']) for i in range(len(r)): self.assert_dicts_are_deeply_equal(r[i], example_images[i]) + +if __name__ == '__main__': + from sys import argv + from kamaki.clients.test import runTestCase + runTestCase(Image, 'Plankton Client', argv[1:]) diff --git a/kamaki/clients/pithos.py b/kamaki/clients/pithos/__init__.py similarity index 100% rename from kamaki/clients/pithos.py rename to kamaki/clients/pithos/__init__.py diff --git a/kamaki/clients/test/pithos.py b/kamaki/clients/pithos/test.py similarity index 99% rename from kamaki/clients/test/pithos.py rename to kamaki/clients/pithos/test.py index 509b142..ac498c5 100644 --- a/kamaki/clients/test/pithos.py +++ b/kamaki/clients/pithos/test.py @@ -1138,3 +1138,8 @@ class Pithos(TestCase): get.mock_calls[-1], call(obj, format='json', version='list')) self.assertEqual(r, info['versions']) + +if __name__ == '__main__': + from sys import argv + from kamaki.clients.test import runTestCase + runTestCase(Pithos, 'Pithos+ Client', argv[1:]) diff --git a/kamaki/clients/test/__init__.py b/kamaki/clients/test.py similarity index 73% rename from kamaki/clients/test/__init__.py rename to kamaki/clients/test.py index 565d6f7..d5ea71a 100644 --- a/kamaki/clients/test/__init__.py +++ b/kamaki/clients/test.py @@ -1,4 +1,4 @@ -# Copyright 2012-2013 GRNET S.A. All rights reserved. +# Copyright 2013 GRNET S.A. All rights reserved. # # Redistribution and use in source and binary forms, with or # without modification, are permitted provided that the following @@ -33,26 +33,12 @@ from unittest import makeSuite, TestSuite, TextTestRunner, TestCase from time import sleep +from inspect import getmembers, isclass -from kamaki.clients.test.astakos import Astakos -from kamaki.clients.test.cyclades import Cyclades -from kamaki.clients.test.image import Image -from kamaki.clients.test.pithos import Pithos - - -def _add_value(foo, value): - def wrap(self): - return foo(self, value) - return wrap - - -def get_test_classes(module=__import__(__name__), name=''): - from inspect import getmembers, isclass - for objname, obj in getmembers(module): - from unittest import TestCase - if (objname == name or not name) and isclass(obj) and ( - issubclass(obj, TestCase)): - yield (obj, objname) +from kamaki.clients.astakos.test import Astakos +from kamaki.clients.cyclades.test import Cyclades +from kamaki.clients.image.test import Image +from kamaki.clients.pithos.test import Pithos class SilentEvent(TestCase): @@ -86,22 +72,41 @@ class SilentEvent(TestCase): self.assertFalse(threads[i].is_alive()) +# TestCase auxiliary methods + +def runTestCase(cls, test_name, args=[]): + suite = TestSuite() + if args: + suite.addTest(cls('_'.join(['test'] + args))) + else: + suite.addTest(makeSuite(cls)) + print('* Test * %s *' % test_name) + TextTestRunner(verbosity=2).run(suite) + + +def _add_value(foo, value): + def wrap(self): + return foo(self, value) + return wrap + + +def get_test_classes(module=__import__(__name__), name=''): + module_stack = [module] + while module_stack: + module = module_stack[-1] + module_stack = module_stack[:-1] + for objname, obj in getmembers(module): + if (objname == name or not name): + if isclass(obj) and objname != 'TestCase' and ( + issubclass(obj, TestCase)): + yield (obj, objname) + + def main(argv): found = False for cls, name in get_test_classes(name=argv[1] if len(argv) > 1 else ''): found = True - args = argv[2:] - suite = TestSuite() - if args: - try: - suite.addTest(cls('_'.join(['test'] + args))) - except ValueError: - print('Test %s not found in %s suite' % (' '.join(args), name)) - continue - else: - suite.addTest(makeSuite(cls)) - print('Test %s' % name) - TextTestRunner(verbosity=2).run(suite) + runTestCase(cls, name, argv[2:]) if not found: print('Test "%s" not found' % ' '.join(argv[1:])) diff --git a/setup.py b/setup.py index 97518ab..e099d59 100755 --- a/setup.py +++ b/setup.py @@ -63,8 +63,11 @@ setup( 'kamaki.cli', 'kamaki.cli.commands', 'kamaki.clients', - 'kamaki.clients.test', 'kamaki.clients.livetest', + 'kamaki.clients.image', + 'kamaki.clients.pithos', + 'kamaki.clients.astakos', + 'kamaki.clients.cyclades', 'kamaki.clients.connection', 'kamaki.clients.commissioning', 'kamaki.clients.quotaholder', -- 1.7.10.4