deleted
[tests.git] / qaapi / qa / tests / Test.py
1 import sys, os
2 from types import *
3 from pprint import pprint
4
5 # Add qa root directory to the path to make
6 # imports easier 
7 path = os.path.dirname(os.path.abspath(__file__))
8 path_parts = path.split(os.sep)
9 sys.path.append(os.sep.join(path_parts[:-2]))
10
11 from qa import utils
12 from qa.logger import log
13 from qa.Config import Config
14
15 class Test:
16     """
17     Base class for all QA test functions. At a minimum all tests
18     must define:
19
20     call(arg1, arg2, ...): method body
21     """
22
23     accepts = []
24     returns = bool
25     status = "current" 
26
27     def call(self, *args):
28         """
29         Method body for test functions. Must override.
30         """
31         return True
32
33     def __init__(self, config = Config()):
34         self.name = self.__class__.__name__
35         self.path=os.path.dirname(sys.argv[0])
36         self.config = config
37         self.errors = []
38
39
40     def __call__(self, *args, **kwds):
41         """
42         Main entry point for test functions. logs methods
43         """
44
45         #(min_args, max_args, defaults) = self.args()
46         
47         # Check that the right number of arguments were passed in
48         #if len(args) < len(min_args) or len(args) > len(max_args):
49         #    raise Exception#, (len(args), len(min_args), len(max_args))
50                 
51         result = self.call(*args, **kwds)
52         return result   
53             
54
55     def args(self):
56         """
57         Returns a tuple:
58
59         ((arg1_name, arg2_name, ...),
60          (arg1_name, arg2_name, ..., optional1_name, optional2_name, ...),
61          (None, None, ..., optional1_default, optional2_default, ...))
62
63         That represents the minimum and maximum sets of arguments that
64         this function accepts and the defaults for the optional arguments.
65         """
66
67         # Inspect call. Remove self from the argument list.
68         max_args = self.call.func_code.co_varnames[1:self.call.func_code.co_argcount]
69         defaults = self.call.func_defaults
70         if defaults is None:
71             defaults = ()
72
73         min_args = max_args[0:len(max_args) - len(defaults)]
74         defaults = tuple([None for arg in min_args]) + defaults
75
76         return (min_args, max_args, defaults)