Rearange client packages 4 uniformity in testing
authorStavros Sachtouris <saxtouri@admin.grnet.gr>
Tue, 12 Mar 2013 15:59:02 +0000 (17:59 +0200)
committerStavros Sachtouris <saxtouri@admin.grnet.gr>
Tue, 12 Mar 2013 15:59:02 +0000 (17:59 +0200)
kamaki/clients/astakos/__init__.py [moved from kamaki/clients/astakos.py with 100% similarity]
kamaki/clients/astakos/test.py [moved from kamaki/clients/test/astakos.py with 96% similarity]
kamaki/clients/cyclades/__init__.py [moved from kamaki/clients/cyclades.py with 100% similarity]
kamaki/clients/cyclades/test.py [moved from kamaki/clients/test/cyclades.py with 99% similarity]
kamaki/clients/image/__init__.py [moved from kamaki/clients/image.py with 100% similarity]
kamaki/clients/image/test.py [moved from kamaki/clients/test/image.py with 98% similarity]
kamaki/clients/pithos/__init__.py [moved from kamaki/clients/pithos.py with 100% similarity]
kamaki/clients/pithos/test.py [moved from kamaki/clients/test/pithos.py with 99% similarity]
kamaki/clients/test.py [moved from kamaki/clients/test/__init__.py with 73% similarity]
setup.py

similarity index 96%
rename from kamaki/clients/test/astakos.py
rename to kamaki/clients/astakos/test.py
index 36e50d6..b343c3b 100644 (file)
@@ -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:])
similarity index 99%
rename from kamaki/clients/test/cyclades.py
rename to kamaki/clients/cyclades/test.py
index f71e060..d982a08 100644 (file)
@@ -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:])
similarity index 98%
rename from kamaki/clients/test/image.py
rename to kamaki/clients/image/test.py
index 6de32e9..155938a 100644 (file)
@@ -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:])
similarity index 99%
rename from kamaki/clients/test/pithos.py
rename to kamaki/clients/pithos/test.py
index 509b142..ac498c5 100644 (file)
@@ -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:])
similarity index 73%
rename from kamaki/clients/test/__init__.py
rename to kamaki/clients/test.py
index 565d6f7..d5ea71a 100644 (file)
@@ -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
 
 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:]))
 
index 97518ab..e099d59 100755 (executable)
--- 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',