| 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() | |
| 23 | 22 |
| 24 diff = REQUIRED_VARS - set(vars) | 23 diff = REQUIRED_VARS - set(vars) |
| 25 if len(diff) > 0: | 24 if len(diff) > 0: |
| 26 warning = ("WARNING: Not all required control " | 25 warning = ("WARNING: Not all required control " |
| 27 "variables were specified in %s. Please define " | 26 "variables were specified in %s. Please define " |
| 28 "%s.") % (self.path, ', '.join(diff)) | 27 "%s.") % (self.path, ', '.join(diff)) |
| 29 if raise_warnings: | 28 if raise_warnings: |
| 30 raise ControlVariableException(warning) | 29 raise ControlVariableException(warning) |
| 31 print textwrap.wrap(warning, 80) | 30 print textwrap.wrap(warning, 80) |
| 32 | 31 |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 self._set_string('test_class', val.lower()) | 127 self._set_string('test_class', val.lower()) |
| 129 | 128 |
| 130 | 129 |
| 131 def set_test_category(self, val): | 130 def set_test_category(self, val): |
| 132 self._set_string('test_category', val.lower()) | 131 self._set_string('test_category', val.lower()) |
| 133 | 132 |
| 134 | 133 |
| 135 def set_test_type(self, val): | 134 def set_test_type(self, val): |
| 136 self._set_option('test_type', val, ['client', 'server']) | 135 self._set_option('test_type', val, ['client', 'server']) |
| 137 | 136 |
| 138 | |
| 139 def set_test_parameters(self, val): | 137 def set_test_parameters(self, val): |
| 140 self._set_set('test_parameters', val) | 138 self._set_set('test_parameters', val) |
| 141 | 139 |
| 142 | 140 |
| 143 def _extract_const(n): | 141 def _extract_const(n): |
| 144 assert(n.__class__ == compiler.ast.Assign) | 142 assert(n.__class__ == compiler.ast.Assign) |
| 145 assert(n.expr.__class__ == compiler.ast.Const) | 143 assert(n.expr.__class__ == compiler.ast.Const) |
| 146 assert(n.expr.value.__class__ in (str, int, float, unicode)) | 144 assert(n.expr.value.__class__ in (str, int, float, unicode)) |
| 147 assert(n.nodes.__class__ == list) | 145 assert(n.nodes.__class__ == list) |
| 148 assert(len(n.nodes) == 1) | 146 assert(len(n.nodes) == 1) |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 187 for n in mod.node.nodes: | 185 for n in mod.node.nodes: |
| 188 for fn in (_extract_const, _extract_name): | 186 for fn in (_extract_const, _extract_name): |
| 189 try: | 187 try: |
| 190 key, val = fn(n) | 188 key, val = fn(n) |
| 191 | 189 |
| 192 vars[key] = val | 190 vars[key] = val |
| 193 except AssertionError, e: | 191 except AssertionError, e: |
| 194 pass | 192 pass |
| 195 | 193 |
| 196 return ControlData(vars, path, raise_warnings) | 194 return ControlData(vars, path, raise_warnings) |
| OLD | NEW |