[stable-2.7] Minor cleanup of code-smell tests. (#45658)

* Minor cleanup of code-smell tests.
* Add exception handling for YAML load..
(cherry picked from commit e7426e3795)

Co-authored-by: Matt Clay <matt@mystile.com>
pull/50748/head
Matt Clay 6 years ago
parent 5fa8d54488
commit 100e4639aa

@ -53,8 +53,8 @@ ILLEGAL_END_CHARS = [
] ]
def check_path(path, dir=False): def check_path(path, is_dir=False):
type_name = 'directory' if dir else 'file' type_name = 'directory' if is_dir else 'file'
parent, file_name = os.path.split(path) parent, file_name = os.path.split(path)
name, ext = os.path.splitext(file_name) name, ext = os.path.splitext(file_name)
@ -85,10 +85,10 @@ def main():
continue continue
for dir_name in dirs: for dir_name in dirs:
check_path(os.path.join(root, dir_name), dir=True) check_path(os.path.join(root, dir_name), is_dir=True)
for file_name in files: for file_name in files:
check_path(os.path.join(root, file_name), dir=False) check_path(os.path.join(root, file_name), is_dir=False)
if __name__ == '__main__': if __name__ == '__main__':

@ -45,7 +45,7 @@ TEST_MAP = {
} }
FILTER_RE = re.compile(r'((.+?)\s*(?P<left>[\w \.\'"]+)(\s*)\|(\s*)(?P<filter>\w+))') FILTER_RE = re.compile(r'((.+?)\s*(?P<left>[\w .\'"]+)(\s*)\|(\s*)(?P<filter>\w+))')
def main(): def main():

@ -129,7 +129,7 @@ def main():
with open(path, 'r') as path_fd: with open(path, 'r') as path_fd:
for line, text in enumerate(path_fd.readlines()): for line, text in enumerate(path_fd.readlines()):
match = re.search(r'(?: |[^C]\()(_)(?: |,|\))', text) match = re.search(r'(?: |[^C]\()(_)(?:[ ,)])', text)
if match: if match:
print('%s:%d:%d: use `dummy` instead of `_` for a variable name' % ( print('%s:%d:%d: use `dummy` instead of `_` for a variable name' % (

Loading…
Cancel
Save