Fix H903 hacking_no_cr

Hacking check was failing to match on lines that should have been
flagged an issue. This fixes the check and adds unit tests to validate
the check is working as expected.

Change-Id: I20e3b54a0c5830565e5d4bbb3bbc8b4921c82fb2
Signed-off-by: Sean McGinnis <sean.mcginnis@gmail.com>
This commit is contained in:
Sean McGinnis 2020-07-22 14:02:08 -05:00
parent 6002520ae3
commit f70a450a7f
2 changed files with 12 additions and 3 deletions

View File

@ -28,9 +28,8 @@ def hacking_no_cr(physical_line):
# upstream fix
H903 import os\r\nimport sys
"""
pos = physical_line.find('\r')
if pos != -1 and pos == (len(physical_line) - 2):
return (pos, "H903: Windows style line endings not allowed in code")
if '\r' in physical_line:
yield (0, "H903: Windows style line endings not allowed in code")
@core.flake8ext

View File

@ -37,3 +37,13 @@ class OthersTestCase(tests.TestCase):
else:
self.assertCheckPasses(other.hacking_delayed_string_interpolation,
line, noqa)
@ddt.unpack
@ddt.data(
(False, 'import os\r\nimport sys'),
(True, 'import os\nimport sys'))
def test_H903_hacking_no_cr(self, passes, line):
if passes:
self.assertCheckPasses(other.hacking_no_cr, line)
else:
self.assertCheckFails(other.hacking_no_cr, line)