Statistics
| Branch: | Tag: | Revision:

root / kamaki / clients / tests / __init__.py @ 420598d0

History | View | Annotate | Download (4.2 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 = 0
71
        if key[0]:
72
            val = self._cnf.get('test', '%s_%s' % key)\
73
                or self._cnf.get(*key)
74
        if not val:
75
            val = self._cnf.get('test', key[1])\
76
                or self._cnf.get('global', key[1])
77
        self._fetched[key] = val
78
        return val
79

    
80

    
81
def init_parser():
82
    parser = ArgumentParser(add_help=False)
83
    parser.add_argument('-h', '--help',
84
        dest='help',
85
        action='store_true',
86
        default=False,
87
        help="Show this help message and exit")
88
    return parser
89

    
90

    
91
def main(argv):
92

    
93
    suiteFew = TestSuite()
94
    """
95
    if len(argv) == 0 or argv[0] == 'pithos':
96
        if len(argv) == 1:
97
            suiteFew.addTest(unittest.makeSuite(testPithos))
98
        else:
99
            suiteFew.addTest(testPithos('test_' + argv[1]))
100
    if len(argv) == 0 or argv[0] == 'cyclades':
101
        if len(argv) == 1:
102
            #suiteFew.addTest(unittest.makeSuite(testCyclades))
103
            suiteFew.addTest(testCyclades('test_000'))
104
        else:
105
            suiteFew.addTest(testCyclades('test_' + argv[1]))
106
    """
107
    if len(argv) == 0 or argv[0] == 'image':
108
        from kamaki.clients.tests.image import Image
109
        if len(argv) == 1:
110
            suiteFew.addTest(makeSuite(Image))
111
        else:
112
            suiteFew.addTest(Image('test_' + argv[1]))
113
    if len(argv) == 0 or argv[0] == 'astakos':
114
        from kamaki.clients.tests.astakos import Astakos
115
        if len(argv) == 1:
116
            suiteFew.addTest(makeSuite(Astakos))
117
        else:
118
            suiteFew.addTest(Astakos('test_' + argv[1]))
119

    
120
    TextTestRunner(verbosity=2).run(suiteFew)
121

    
122
if __name__ == '__main__':
123
    parser = init_parser()
124
    args, argv = parser.parse_known_args()
125
    if len(argv) > 2 or getattr(args, 'help') or len(argv) < 1:
126
        raise Exception('\tusage: tests.py <group> [command]')
127
    main(argv)