Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(104)

Side by Side Diff: recipe_engine/recipe_test_api.py

Issue 2707593002: Whitelist allowed test names
Patch Set: Use correct regex Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | recipe_engine/unittests/recipe_test_api_test.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright 2016 The LUCI Authors. All rights reserved. 1 # Copyright 2016 The LUCI Authors. All rights reserved.
2 # Use of this source code is governed under the Apache License, Version 2.0 2 # Use of this source code is governed under the Apache License, Version 2.0
3 # that can be found in the LICENSE file. 3 # that can be found in the LICENSE file.
4 4
5 import contextlib 5 import contextlib
6 import inspect 6 import inspect
7 import re
7 8
8 from collections import namedtuple, defaultdict 9 from collections import namedtuple, defaultdict
9 10
10 from .util import ModuleInjectionSite, static_call, static_wraps 11 from .util import ModuleInjectionSite, static_call, static_wraps
11 from .types import freeze 12 from .types import freeze
12 13
13 def combineify(name, dest, a, b, overwrite=False): 14 def combineify(name, dest, a, b, overwrite=False):
14 """ 15 """
15 Combines dictionary members in two objects into a third one using addition. 16 Combines dictionary members in two objects into a third one using addition.
16 17
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 return ret 181 return ret
181 182
182 def __repr__(self): 183 def __repr__(self):
183 return "ModuleTestData(%r)" % super(ModuleTestData, self).__repr__() 184 return "ModuleTestData(%r)" % super(ModuleTestData, self).__repr__()
184 185
185 186
186 PostprocessHook = namedtuple( 187 PostprocessHook = namedtuple(
187 'PostprocessHook', 'func args kwargs filename lineno') 188 'PostprocessHook', 'func args kwargs filename lineno')
188 189
189 190
191 def is_valid_test_name(name):
192 return bool(re.match(r'^(\w)+$', name))
193
194
190 class TestData(BaseTestData): 195 class TestData(BaseTestData):
191 def __init__(self, name=None): 196 def __init__(self, name=None):
192 super(TestData, self).__init__() 197 super(TestData, self).__init__()
198 # Allow empty names; sometimes we create test datas to merge two test datas
199 # together.
200 if name and not is_valid_test_name(name):
201 raise ValueError("Invalid test name %r" % name)
202
193 self.name = name 203 self.name = name
194 self.properties = {} # key -> val 204 self.properties = {} # key -> val
195 self.mod_data = defaultdict(ModuleTestData) 205 self.mod_data = defaultdict(ModuleTestData)
196 self.step_data = defaultdict(StepTestData) 206 self.step_data = defaultdict(StepTestData)
197 self.depend_on_data = {} 207 self.depend_on_data = {}
198 self.expected_exception = None 208 self.expected_exception = None
199 self.post_process_hooks = [] # list(PostprocessHook) 209 self.post_process_hooks = [] # list(PostprocessHook)
200 210
201 def __add__(self, other): 211 def __add__(self, other):
202 assert isinstance(other, TestData) 212 assert isinstance(other, TestData)
(...skipping 443 matching lines...) Expand 10 before | Expand all | Expand 10 after
646 ) 656 )
647 """ 657 """
648 ret = TestData() 658 ret = TestData()
649 try: 659 try:
650 stk = inspect.stack() 660 stk = inspect.stack()
651 _, filename, lineno, _, _, _ = stk[1] 661 _, filename, lineno, _, _, _ = stk[1]
652 finally: 662 finally:
653 del stk 663 del stk
654 ret.post_process(func, args, kwargs, filename, lineno) 664 ret.post_process(func, args, kwargs, filename, lineno)
655 return ret 665 return ret
OLDNEW
« no previous file with comments | « no previous file | recipe_engine/unittests/recipe_test_api_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698