Skip to content

Commit 60293a7

Browse files
author
Craig Cornelius
authored
Fix some warnings with regex (#485)
* Fix some warnings with regex * Refactor names of regular expressions * Move global regex to locale * Small updates * Refactor some regexs into common code.
1 parent 28fd834 commit 60293a7

File tree

3 files changed

+13
-11
lines changed

3 files changed

+13
-11
lines changed

testgen/common.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# -*- coding: utf-8 -*-
2+
3+
import re
4+
5+
# Commonly used regular expressions and other code
6+
RE_BLANK_LINE = re.compile(r"^\s*$")
7+
RE_COMMENT_LINE = re.compile(r"^\s*#")

testgen/generators/lang_names.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
# -*- coding: utf-8 -*-
2+
import common
3+
24
import os
35
import json
46
import re
57
import logging
68
from generators.base import DataGenerator
79

8-
reblankline = re.compile("^\s*$")
9-
10-
1110
class LangNamesGenerator(DataGenerator):
1211
json_test = {"test_type": "lang_names"}
1312
json_verify = {"test_type": "lang_names"}
@@ -57,7 +56,6 @@ def languageNameDescr(self):
5756

5857
def generateLanguageNameTestDataObjects(self, rawtestdata):
5958
# Get the JSON data for tests and verification for language names
60-
recommentline = re.compile("^\s*#")
6159
count = 0
6260

6361
jtests = []
@@ -68,7 +66,7 @@ def generateLanguageNameTestDataObjects(self, rawtestdata):
6866
num_samples = len(test_lines)
6967
max_digits = self.computeMaxDigitsForCount(num_samples)
7068
for item in test_lines:
71-
if not (recommentline.match(item) or reblankline.match(item)):
69+
if not (common.RE_COMMENT_LINE.match(item) or common.RE_BLANK_LINE.match(item)):
7270
test_data = self.parseLanguageNameData(item)
7371
if test_data == None:
7472
logging.debug(

testgen/generators/localeDisplayNames.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
# -*- coding: utf-8 -*-
2+
import common
3+
24
import os
35
import json
46
import re
57
import logging
68
from generators.base import DataGenerator
79

8-
reblankline = re.compile("^\s*$")
9-
10-
1110
class LocaleNamesGenerator(DataGenerator):
1211
json_test = {"test_type": "lang_names"}
1312
json_verify = {"test_type": "lang_names"}
@@ -59,8 +58,6 @@ def languageNameDescr(self):
5958

6059
def generateLanguageNameTestDataObjects(self, rawtestdata):
6160
# Get the JSON data for tests and verification for language names
62-
recommentline = re.compile("^\s*#")
63-
6461
set_locale = re.compile(r"@locale=(\w+)")
6562
set_languageDisplay = re.compile(r"@languageDisplay=(\w+)")
6663

@@ -78,7 +75,7 @@ def generateLanguageNameTestDataObjects(self, rawtestdata):
7875
language_display = 'standard'
7976

8077
for item in test_lines:
81-
if not (recommentline.match(item) or reblankline.match(item)):
78+
if not (common.RE_COMMENT_LINE.match(item) or common.RE_BLANK_LINE.match(item)):
8279

8380
locale_match = set_locale.match(item)
8481
if locale_match:

0 commit comments

Comments
 (0)