Chromium Code Reviews| Index: recipe_engine/recipe_test_api.py |
| diff --git a/recipe_engine/recipe_test_api.py b/recipe_engine/recipe_test_api.py |
| index e9e0431d86c7a4a68f8649ee32ff4315d0dbe768..cf1147d7de1361cb303884938ac5a2d6c67a9ff4 100644 |
| --- a/recipe_engine/recipe_test_api.py |
| +++ b/recipe_engine/recipe_test_api.py |
| @@ -4,6 +4,7 @@ |
| import contextlib |
| import inspect |
| +import re |
| from collections import namedtuple, defaultdict |
| @@ -186,10 +187,25 @@ class ModuleTestData(BaseTestData, dict): |
| PostprocessHook = namedtuple( |
| 'PostprocessHook', 'func args kwargs filename lineno') |
| +def is_valid_test_name(name): |
| + # * is there to make the match greedy, so it matches the whole word, rather |
|
Paweł Hajdan Jr.
2017/02/21 09:53:31
nit: No need to explain regex syntax IMO.
|
| + # than just the first character of a name |
| + match = re.match(r'(\w)*', name) |
|
dnj
2017/02/18 00:15:29
Why not: "name.isalnum()"? Also will reject whites
dnj
2017/02/18 01:27:41
Ah boo :(
Could do:
re.match(r'[a-zA-Z0-9_]*')
I
Paweł Hajdan Jr.
2017/02/21 09:53:31
Let's use ^, $, and +, i.e.
r'^(\w)+$'
Then we d
|
| + if not match: |
| + return False |
| + |
| + # Catches a case of a name with a space in it. |
| + return len(match.group(0)) == len(name) |
| + |
| class TestData(BaseTestData): |
| def __init__(self, name=None): |
| super(TestData, self).__init__() |
| + # Allow empty names; sometimes we create test datas to merge two test datas |
| + # together. |
| + if name and not is_valid_test_name(name): |
| + raise ValueError("Invalid test name %r" % name) |
|
Paweł Hajdan Jr.
2017/02/21 09:53:31
nit: Single quotes ' instead of double "
Also, ex
|
| + |
| self.name = name |
| self.properties = {} # key -> val |
| self.mod_data = defaultdict(ModuleTestData) |