make things ugly to make flake8 happy

This commit is contained in:
Spencer Young
2020-04-03 21:38:57 -07:00
parent a68a80143a
commit efd597f00f
2 changed files with 19 additions and 15 deletions

View File

@@ -92,11 +92,13 @@ class CommandLineTestCase(unittest.TestCase):
'dos.yml': '---\r\n' 'dos.yml': '---\r\n'
'dos: true', 'dos: true',
# UTF-16 Little Endian BOM # UTF-16 Little Endian BOM
'non-ascii/utf16le': b'\xff\xfe' + u'---\nutf16le: true\n'.encode('utf-16-le'), 'non-ascii/utf-16-le':
b'\xff\xfe' + u'---\nutf16le: true\n'.encode('utf-16-le'),
# UTF-16 Big Endian # UTF-16 Big Endian
'non-ascii/utf16be': b'\xfe\xff' + u'---\nutf16be: true\n'.encode('utf-16-be'), 'non-ascii/utf-16-be':
b'\xfe\xff' + u'---\nutf16be: true\n'.encode('utf-16-be'),
# UTF-8 BOM # UTF-8 BOM
'non-ascii/utf8': b'\xef\xbb\xbf---\nutf8: true\n', 'non-ascii/utf-8': b'\xef\xbb\xbf---\nutf8: true\n',
}) })
@classmethod @classmethod
@@ -177,9 +179,9 @@ class CommandLineTestCase(unittest.TestCase):
os.path.join(self.wd, 'dos.yml'), os.path.join(self.wd, 'dos.yml'),
os.path.join(self.wd, 'empty.yml'), os.path.join(self.wd, 'empty.yml'),
os.path.join(self.wd, 'no-yaml.json'), os.path.join(self.wd, 'no-yaml.json'),
os.path.join(self.wd, 'non-ascii/utf16be'), os.path.join(self.wd, 'non-ascii/utf-16-be'),
os.path.join(self.wd, 'non-ascii/utf16le'), os.path.join(self.wd, 'non-ascii/utf-16-le'),
os.path.join(self.wd, 'non-ascii/utf8'), os.path.join(self.wd, 'non-ascii/utf-8'),
os.path.join(self.wd, 'non-ascii/éçäγλνπ¥/utf-8'), os.path.join(self.wd, 'non-ascii/éçäγλνπ¥/utf-8'),
os.path.join(self.wd, 's/s/s/s/s/s/s/s/s/s/s/s/s/s/s/file.yaml'), os.path.join(self.wd, 's/s/s/s/s/s/s/s/s/s/s/s/s/s/s/file.yaml'),
os.path.join(self.wd, 'sub/ok.yaml'), os.path.join(self.wd, 'sub/ok.yaml'),
@@ -197,9 +199,9 @@ class CommandLineTestCase(unittest.TestCase):
os.path.join(self.wd, 'dos.yml'), os.path.join(self.wd, 'dos.yml'),
os.path.join(self.wd, 'empty.yml'), os.path.join(self.wd, 'empty.yml'),
os.path.join(self.wd, 'no-yaml.json'), os.path.join(self.wd, 'no-yaml.json'),
os.path.join(self.wd, 'non-ascii/utf16be'), os.path.join(self.wd, 'non-ascii/utf-16-be'),
os.path.join(self.wd, 'non-ascii/utf16le'), os.path.join(self.wd, 'non-ascii/utf-16-le'),
os.path.join(self.wd, 'non-ascii/utf8'), os.path.join(self.wd, 'non-ascii/utf-8'),
os.path.join(self.wd, 'non-ascii/éçäγλνπ¥/utf-8'), os.path.join(self.wd, 'non-ascii/éçäγλνπ¥/utf-8'),
os.path.join(self.wd, 's/s/s/s/s/s/s/s/s/s/s/s/s/s/s/file.yaml'), os.path.join(self.wd, 's/s/s/s/s/s/s/s/s/s/s/s/s/s/s/file.yaml'),
os.path.join(self.wd, 'sub/ok.yaml'), os.path.join(self.wd, 'sub/ok.yaml'),
@@ -531,19 +533,19 @@ class CommandLineTestCase(unittest.TestCase):
(ctx.returncode, ctx.stdout, ctx.stderr), (1, expected_out, '')) (ctx.returncode, ctx.stdout, ctx.stderr), (1, expected_out, ''))
def test_encoding_detection_utf16le(self): def test_encoding_detection_utf16le(self):
path = os.path.join(self.wd, 'non-ascii/utf16le') path = os.path.join(self.wd, 'non-ascii/utf-16-le')
with RunContext(self) as ctx: with RunContext(self) as ctx:
cli.run(('-f', 'parsable', path)) cli.run(('-f', 'parsable', path))
self.assertEqual((ctx.returncode, ctx.stdout, ctx.stderr), (0, '', '')) self.assertEqual((ctx.returncode, ctx.stdout, ctx.stderr), (0, '', ''))
def test_encoding_detection_utf16be(self): def test_encoding_detection_utf16be(self):
path = os.path.join(self.wd, 'non-ascii/utf16be') path = os.path.join(self.wd, 'non-ascii/utf-16-be')
with RunContext(self) as ctx: with RunContext(self) as ctx:
cli.run(('-f', 'parsable', path)) cli.run(('-f', 'parsable', path))
self.assertEqual((ctx.returncode, ctx.stdout, ctx.stderr), (0, '', '')) self.assertEqual((ctx.returncode, ctx.stdout, ctx.stderr), (0, '', ''))
def test_encoding_detection_utf8(self): def test_encoding_detection_utf8(self):
path = os.path.join(self.wd, 'non-ascii/utf8') path = os.path.join(self.wd, 'non-ascii/utf-8')
with RunContext(self) as ctx: with RunContext(self) as ctx:
cli.run(('-f', 'parsable', path)) cli.run(('-f', 'parsable', path))
self.assertEqual((ctx.returncode, ctx.stdout, ctx.stderr), (0, '', '')) self.assertEqual((ctx.returncode, ctx.stdout, ctx.stderr), (0, '', ''))

View File

@@ -17,13 +17,14 @@
from __future__ import print_function from __future__ import print_function
import argparse import argparse
import chardet
import contextlib import contextlib
import io import io
import os import os
import platform import platform
import sys import sys
import chardet
from yamllint import APP_DESCRIPTION, APP_NAME, APP_VERSION from yamllint import APP_DESCRIPTION, APP_NAME, APP_VERSION
from yamllint import linter from yamllint import linter
from yamllint.config import YamlLintConfig, YamlLintConfigError from yamllint.config import YamlLintConfig, YamlLintConfigError
@@ -38,10 +39,11 @@ def yamlopen(fp, **iowrapper_kwargs):
raw_data = raw_file.read() raw_data = raw_file.read()
encoding = chardet.detect(raw_data).get('encoding') or 'utf-8' encoding = chardet.detect(raw_data).get('encoding') or 'utf-8'
raw_file.seek(0) raw_file.seek(0)
with io.TextIOWrapper(raw_file, encoding=encoding, **iowrapper_kwargs) as decoded: with io.TextIOWrapper(
raw_file, encoding=encoding, **iowrapper_kwargs
) as decoded:
yield decoded yield decoded
def find_files_recursively(items, conf): def find_files_recursively(items, conf):
for item in items: for item in items:
if os.path.isdir(item): if os.path.isdir(item):