| OLD | NEW | 
|---|
| 1 # | 1 # | 
| 2 # Copyright 2008 Google Inc. Released under the GPL v2 | 2 # Copyright 2008 Google Inc. Released under the GPL v2 | 
| 3 | 3 | 
| 4 import compiler, textwrap, types | 4 import compiler, textwrap, types | 
| 5 | 5 | 
| 6 | 6 | 
| 7 REQUIRED_VARS = set(['author', 'doc', 'name', 'time', 'test_class', | 7 REQUIRED_VARS = set(['author', 'doc', 'name', 'time', 'test_class', | 
| 8                      'test_category', 'test_type']) | 8                      'test_category', 'test_type']) | 
| 9 | 9 | 
| 10 class ControlVariableException(Exception): | 10 class ControlVariableException(Exception): | 
| 11     pass | 11     pass | 
| 12 | 12 | 
| 13 | 13 | 
| 14 class ControlData(object): | 14 class ControlData(object): | 
| 15     def __init__(self, vars, path, raise_warnings=False): | 15     def __init__(self, vars, path, raise_warnings=False): | 
| 16         # Defaults | 16         # Defaults | 
| 17         self.path = path | 17         self.path = path | 
| 18         self.dependencies = set() | 18         self.dependencies = set() | 
| 19         self.experimental = False | 19         self.experimental = False | 
| 20         self.run_verify = True | 20         self.run_verify = True | 
| 21         self.sync_count = 1 | 21         self.sync_count = 1 | 
|  | 22         self.test_parameters = set() | 
| 22 | 23 | 
| 23         diff = REQUIRED_VARS - set(vars) | 24         diff = REQUIRED_VARS - set(vars) | 
| 24         if len(diff) > 0: | 25         if len(diff) > 0: | 
| 25             warning = ("WARNING: Not all required control " | 26             warning = ("WARNING: Not all required control " | 
| 26                        "variables were specified in %s.  Please define " | 27                        "variables were specified in %s.  Please define " | 
| 27                        "%s.") % (self.path, ', '.join(diff)) | 28                        "%s.") % (self.path, ', '.join(diff)) | 
| 28             if raise_warnings: | 29             if raise_warnings: | 
| 29                 raise ControlVariableException(warning) | 30                 raise ControlVariableException(warning) | 
| 30             print textwrap.wrap(warning, 80) | 31             print textwrap.wrap(warning, 80) | 
| 31 | 32 | 
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 127         self._set_string('test_class', val.lower()) | 128         self._set_string('test_class', val.lower()) | 
| 128 | 129 | 
| 129 | 130 | 
| 130     def set_test_category(self, val): | 131     def set_test_category(self, val): | 
| 131         self._set_string('test_category', val.lower()) | 132         self._set_string('test_category', val.lower()) | 
| 132 | 133 | 
| 133 | 134 | 
| 134     def set_test_type(self, val): | 135     def set_test_type(self, val): | 
| 135         self._set_option('test_type', val, ['client', 'server']) | 136         self._set_option('test_type', val, ['client', 'server']) | 
| 136 | 137 | 
|  | 138 | 
| 137     def set_test_parameters(self, val): | 139     def set_test_parameters(self, val): | 
| 138         self._set_set('test_parameters', val) | 140         self._set_set('test_parameters', val) | 
| 139 | 141 | 
| 140 | 142 | 
| 141 def _extract_const(n): | 143 def _extract_const(n): | 
| 142     assert(n.__class__ == compiler.ast.Assign) | 144     assert(n.__class__ == compiler.ast.Assign) | 
| 143     assert(n.expr.__class__ == compiler.ast.Const) | 145     assert(n.expr.__class__ == compiler.ast.Const) | 
| 144     assert(n.expr.value.__class__ in (str, int, float, unicode)) | 146     assert(n.expr.value.__class__ in (str, int, float, unicode)) | 
| 145     assert(n.nodes.__class__ == list) | 147     assert(n.nodes.__class__ == list) | 
| 146     assert(len(n.nodes) == 1) | 148     assert(len(n.nodes) == 1) | 
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 185     for n in mod.node.nodes: | 187     for n in mod.node.nodes: | 
| 186         for fn in (_extract_const, _extract_name): | 188         for fn in (_extract_const, _extract_name): | 
| 187             try: | 189             try: | 
| 188                 key, val = fn(n) | 190                 key, val = fn(n) | 
| 189 | 191 | 
| 190                 vars[key] = val | 192                 vars[key] = val | 
| 191             except AssertionError, e: | 193             except AssertionError, e: | 
| 192                 pass | 194                 pass | 
| 193 | 195 | 
| 194     return ControlData(vars, path, raise_warnings) | 196     return ControlData(vars, path, raise_warnings) | 
| OLD | NEW | 
|---|