Commit c64e3902 authored by Anthony Polito's avatar Anthony Polito Committed by LUCI CQ

fix encoding for _GetYapfIgnorePatterns so it supports utf-8

Bug: 1204441
Change-Id: I36b963d69b5dec9e609258055b800b14d398b2b8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/2864013Reviewed-by: 's avatarEdward Lesmes <ehmaldonado@chromium.org>
Commit-Queue: Edward Lesmes <ehmaldonado@chromium.org>
Auto-Submit: Anthony Polito <apolito@google.com>
parent 1e59a247
......@@ -666,13 +666,12 @@ def _GetYapfIgnorePatterns(top_dir):
if not os.path.exists(yapfignore_file):
return ignore_patterns
with open(yapfignore_file) as f:
for line in f.readlines():
stripped_line = line.strip()
# Comments and blank lines should be ignored.
if stripped_line.startswith('#') or stripped_line == '':
continue
ignore_patterns.add(stripped_line)
for line in gclient_utils.FileRead(yapfignore_file).split('\n'):
stripped_line = line.strip()
# Comments and blank lines should be ignored.
if stripped_line.startswith('#') or stripped_line == '':
continue
ignore_patterns.add(stripped_line)
return ignore_patterns
......
......@@ -3947,8 +3947,8 @@ class CMDFormatTestCase(unittest.TestCase):
super(CMDFormatTestCase, self).tearDown()
def _make_temp_file(self, fname, contents):
with open(os.path.join(self._top_dir, fname), 'w') as tf:
tf.write('\n'.join(contents))
gclient_utils.FileWrite(os.path.join(self._top_dir, fname),
('\n'.join(contents)))
def _make_yapfignore(self, contents):
self._make_temp_file('.yapfignore', contents)
......@@ -4063,6 +4063,18 @@ class CMDFormatTestCase(unittest.TestCase):
]
self._check_yapf_filtering(files, expected)
def testYapfHandleUtf8(self):
self._make_yapfignore(['test.py', 'test_🌐.py'])
files = [
'test.py',
'test_🌐.py',
'test2.py',
]
expected = [
'test2.py',
]
self._check_yapf_filtering(files, expected)
def testYapfignoreBlankLines(self):
self._make_yapfignore(['test.py', '', '', 'test2.py'])
files = [
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment