root / kamaki / clients / tests / __init__.py @ 1f0370c9
History | View | Annotate | Download (4.1 kB)
1 |
# Copyright 2012-2013 GRNET S.A. All rights reserved.
|
---|---|
2 |
#
|
3 |
# Redistribution and use in source and binary forms, with or
|
4 |
# without modification, are permitted provided that the following
|
5 |
# conditions are met:
|
6 |
#
|
7 |
# 1. Redistributions of source code must retain the above
|
8 |
# copyright notice, this list of conditions and the following
|
9 |
# disclaimer.
|
10 |
#
|
11 |
# 2. Redistributions in binary form must reproduce the above
|
12 |
# copyright notice, this list of conditions and the following
|
13 |
# disclaimer in the documentation and/or other materials
|
14 |
# provided with the distribution.
|
15 |
#
|
16 |
# THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
|
17 |
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
18 |
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
19 |
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
|
20 |
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
21 |
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
22 |
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
23 |
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
24 |
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
25 |
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
26 |
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
27 |
# POSSIBILITY OF SUCH DAMAGE.
|
28 |
#
|
29 |
# The views and conclusions contained in the software and
|
30 |
# documentation are those of the authors and should not be
|
31 |
# interpreted as representing official policies, either expressed
|
32 |
# or implied, of GRNET S.A.
|
33 |
|
34 |
from unittest import TestCase, TestSuite, makeSuite, TextTestRunner |
35 |
from argparse import ArgumentParser |
36 |
|
37 |
from kamaki.cli.config import Config |
38 |
|
39 |
|
40 |
def _add_value(foo, value): |
41 |
def wrap(self): |
42 |
return foo(self, value) |
43 |
return wrap
|
44 |
|
45 |
|
46 |
class Generic(TestCase): |
47 |
|
48 |
_cnf = None
|
49 |
_grp = None
|
50 |
_fetched = {} |
51 |
|
52 |
def __init__(self, specific=None, config_file=None, group=None): |
53 |
super(Generic, self).__init__(specific) |
54 |
self._cnf = Config(config_file)
|
55 |
self._grp = group
|
56 |
|
57 |
def __getitem__(self, key): |
58 |
key = self._key(key)
|
59 |
try:
|
60 |
return self._fetched[key] |
61 |
except KeyError: |
62 |
return self._get_from_cnf(key) |
63 |
|
64 |
def _key(self, key): |
65 |
return ('', key) if isinstance(key, str)\ |
66 |
else ('', key[0]) if len(key) == 1\ |
67 |
else key
|
68 |
|
69 |
def _get_from_cnf(self, key): |
70 |
val = (self._cnf.get('test', '%s_%s' % key) if key[0] else None)\ |
71 |
or self._cnf.get(*key)\ |
72 |
or self._cnf.get('test', key[1])\ |
73 |
or self._cnf.get('global', key[1]) |
74 |
self._fetched[key] = val
|
75 |
return val
|
76 |
|
77 |
|
78 |
def init_parser(): |
79 |
parser = ArgumentParser(add_help=False)
|
80 |
parser.add_argument('-h', '--help', |
81 |
dest='help',
|
82 |
action='store_true',
|
83 |
default=False,
|
84 |
help="Show this help message and exit")
|
85 |
return parser
|
86 |
|
87 |
|
88 |
def main(argv): |
89 |
|
90 |
suiteFew = TestSuite() |
91 |
"""
|
92 |
if len(argv) == 0 or argv[0] == 'pithos':
|
93 |
if len(argv) == 1:
|
94 |
suiteFew.addTest(unittest.makeSuite(testPithos))
|
95 |
else:
|
96 |
suiteFew.addTest(testPithos('test_' + argv[1]))
|
97 |
if len(argv) == 0 or argv[0] == 'cyclades':
|
98 |
if len(argv) == 1:
|
99 |
#suiteFew.addTest(unittest.makeSuite(testCyclades))
|
100 |
suiteFew.addTest(testCyclades('test_000'))
|
101 |
else:
|
102 |
suiteFew.addTest(testCyclades('test_' + argv[1]))
|
103 |
if len(argv) == 0 or argv[0] == 'image':
|
104 |
if len(argv) == 1:
|
105 |
suiteFew.addTest(unittest.makeSuite(testImage))
|
106 |
else:
|
107 |
suiteFew.addTest(testImage('test_' + argv[1]))
|
108 |
"""
|
109 |
if len(argv) == 0 or argv[0] == 'astakos': |
110 |
from kamaki.clients.tests.astakos import Astakos |
111 |
if len(argv) == 1: |
112 |
suiteFew.addTest(makeSuite(Astakos)) |
113 |
else:
|
114 |
suiteFew.addTest(Astakos('test_' + argv[1])) |
115 |
|
116 |
TextTestRunner(verbosity=2).run(suiteFew)
|
117 |
|
118 |
if __name__ == '__main__': |
119 |
parser = init_parser() |
120 |
args, argv = parser.parse_known_args() |
121 |
if len(argv) > 2 or getattr(args, 'help') or len(argv) < 1: |
122 |
raise Exception('\tusage: tests.py <group> [command]') |
123 |
main(argv) |