Skip to content

Commit

Permalink
Improve check_newlines utility to also check the presence of two cons…
Browse files Browse the repository at this point in the history
…ecutive \r line endings
  • Loading branch information
ptormene committed Oct 23, 2023
1 parent dcaf97a commit a5c0d8f
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion openquake/baselib/tests/flake8_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ def get_long_funcs(mod_or_pkg, maxlen):
@numba.njit
def check_newlines(bytes):
"""
:returns: 0 if the newlines are \r\n, 1 for \n and 2 for \r
:returns: 0 if the newlines are \r\n, 1 for \n, 2 for \r and 3 for two
consecutive \r
"""
n1 = len(bytes) - 1
for i, byte in enumerate(bytes):
Expand All @@ -84,6 +85,8 @@ def check_newlines(bytes):
elif byte == CR:
if (i < n1 and bytes[i+1] != LF) or i == n1:
return 2 # \r ending
if i > 0 and bytes[i-1] == CR:
return 3
return 0


Expand Down Expand Up @@ -155,6 +158,9 @@ def test_csv(OVERWRITE=False):
raise ValueError('Found \\n line ending in %s' % fname)
elif error == 2:
raise ValueError('Found \\r line ending in %s' % fname)
elif error == 3:
raise ValueError('Found two consecutive \\r line endings'
' in %s' % fname)


def test_forbid_long_funcs():
Expand Down

0 comments on commit a5c0d8f

Please sign in to comment.