From e46e7407a14ef728f3f54ed68a093004f897e696 Mon Sep 17 00:00:00 2001 From: jack1142 <6032823+jack1142@users.noreply.github.com> Date: Sun, 14 Mar 2021 19:23:08 +0100 Subject: [PATCH 1/6] Ignore line endings in exclude-file --- codespell_lib/_codespell.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/codespell_lib/_codespell.py b/codespell_lib/_codespell.py index b0462ebd20..167e20d5f5 100644 --- a/codespell_lib/_codespell.py +++ b/codespell_lib/_codespell.py @@ -613,7 +613,7 @@ def parse_ignore_words_option(ignore_words_option: List[str]) -> Set[str]: def build_exclude_hashes(filename: str, exclude_lines: Set[str]) -> None: with open(filename, encoding="utf-8") as f: for line in f: - exclude_lines.add(line) + exclude_lines.add(line.rstrip()) def build_ignore_words(filename: str, ignore_words: Set[str]) -> None: @@ -843,7 +843,7 @@ def parse_file( return bad_count for i, line in enumerate(lines): - if line in exclude_lines: + if line.rstrip() in exclude_lines: continue fixed_words = set() From 8c3808c9dd4c9bcba92599a09b96741ba1356cb9 Mon Sep 17 00:00:00 2001 From: jack1142 <6032823+jack1142@users.noreply.github.com> Date: Sun, 14 Mar 2021 19:25:41 +0100 Subject: [PATCH 2/6] Update the test for exclude-file --- codespell_lib/tests/test_basic.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/codespell_lib/tests/test_basic.py b/codespell_lib/tests/test_basic.py index cb000afd5f..f841cb3edd 100644 --- a/codespell_lib/tests/test_basic.py +++ b/codespell_lib/tests/test_basic.py @@ -352,7 +352,7 @@ def test_exclude_file( """Test exclude file functionality.""" d = str(tmpdir) with open(op.join(d, "bad.txt"), "wb") as f: - f.write(b"1 abandonned 1\n2 abandonned 2\n") + f.write(b"1 abandonned 1\r\n2 abandonned 2\r\n") bad_name = f.name assert cs.main(bad_name) == 2 with open(op.join(d, "tmp.txt"), "wb") as f: From c7fb2f3ef26b5096fb2c2cff44d2a28885b3346d Mon Sep 17 00:00:00 2001 From: jack1142 <6032823+jack1142@users.noreply.github.com> Date: Thu, 25 Mar 2021 13:33:19 +0100 Subject: [PATCH 3/6] Improve `test_exclude_file` --- codespell_lib/tests/test_basic.py | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/codespell_lib/tests/test_basic.py b/codespell_lib/tests/test_basic.py index f841cb3edd..b145a886fb 100644 --- a/codespell_lib/tests/test_basic.py +++ b/codespell_lib/tests/test_basic.py @@ -352,12 +352,26 @@ def test_exclude_file( """Test exclude file functionality.""" d = str(tmpdir) with open(op.join(d, "bad.txt"), "wb") as f: - f.write(b"1 abandonned 1\r\n2 abandonned 2\r\n") + # check all possible combinations of lines to ignore and ignores + combinations = "".join( + "%(n)s abandonned %(n)s\n" + "%(n)s abandonned %(n)s\r\n" + "%(n)s abandonned %(n)s \n" + "%(n)s abandonned %(n)s \r\n" % {"n": n} + for n in range(1, 5) + ) + f.write((combinations + "5 abandonned 5\n6 abandonned 6").encode("utf-8")) bad_name = f.name - assert cs.main(bad_name) == 2 + assert cs.main(bad_name) == 18 with open(op.join(d, "tmp.txt"), "wb") as f: - f.write(b"1 abandonned 1\n") - assert cs.main(bad_name) == 2 + f.write( + "1 abandonned 1\n" + "2 abandonned 2\r\n" + "3 abandonned 3 \n" + "4 abandonned 4 \r\n" + "6 abandonned 6\n".encode("utf-8") + ) + assert cs.main(bad_name) == 18 assert cs.main("-x", f.name, bad_name) == 1 From 36ba85f3763a58e191bca3ace1e924aace1283a7 Mon Sep 17 00:00:00 2001 From: jack1142 <6032823+jack1142@users.noreply.github.com> Date: Thu, 25 Mar 2021 13:37:58 +0100 Subject: [PATCH 4/6] Cover the same cases in `test_ignore_dictionary` --- codespell_lib/tests/test_basic.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/codespell_lib/tests/test_basic.py b/codespell_lib/tests/test_basic.py index b145a886fb..1894f10ac1 100644 --- a/codespell_lib/tests/test_basic.py +++ b/codespell_lib/tests/test_basic.py @@ -308,11 +308,19 @@ def test_ignore_dictionary( """Test ignore dictionary functionality.""" d = str(tmpdir) with open(op.join(d, "bad.txt"), "w") as f: - f.write("1 abandonned 1\n2 abandonned 2\nabondon\n") + f.write( + "1 abandonned 1\n" + "2 abandonned 2\n" + "3 abilty 3\n" + "4 abilty 4\n" + "5 ackward 5\n" + "6 ackward 6\n" + "abondon\n" + ) bad_name = f.name - assert cs.main(bad_name) == 3 + assert cs.main(bad_name) == 7 with open(op.join(d, "ignore.txt"), "w") as f: - f.write("abandonned\n") + f.write("abandonned\nabilty\r\nackward ") assert cs.main("-I", f.name, bad_name) == 1 From c47b7a1d1a6ad4140b9176b30ae3536a804bedc7 Mon Sep 17 00:00:00 2001 From: jack1142 <6032823+jack1142@users.noreply.github.com> Date: Tue, 6 Apr 2021 21:20:32 +0200 Subject: [PATCH 5/6] Add lines with CRLF to test_ignore_dictionary Co-authored-by: Peter Newman --- codespell_lib/tests/test_basic.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/codespell_lib/tests/test_basic.py b/codespell_lib/tests/test_basic.py index 1894f10ac1..64a640f5ce 100644 --- a/codespell_lib/tests/test_basic.py +++ b/codespell_lib/tests/test_basic.py @@ -311,14 +311,17 @@ def test_ignore_dictionary( f.write( "1 abandonned 1\n" "2 abandonned 2\n" - "3 abilty 3\n" + "3 abandonned 3\r\n" "4 abilty 4\n" - "5 ackward 5\n" - "6 ackward 6\n" + "5 abilty 5\n" + "6 abilty 6\r\n" + "7 ackward 7\n" + "8 ackward 8\n" + "9 ackward 9\r\n" "abondon\n" ) bad_name = f.name - assert cs.main(bad_name) == 7 + assert cs.main(bad_name) == 10 with open(op.join(d, "ignore.txt"), "w") as f: f.write("abandonned\nabilty\r\nackward ") assert cs.main("-I", f.name, bad_name) == 1 From f7a398bfa895080fbf8daa0d7b262bf02dc0c268 Mon Sep 17 00:00:00 2001 From: Jakub Kuczys Date: Fri, 7 Apr 2023 16:09:29 +0200 Subject: [PATCH 6/6] Switch percent-format to f-string --- codespell_lib/tests/test_basic.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/codespell_lib/tests/test_basic.py b/codespell_lib/tests/test_basic.py index 5bf241074c..6c48aa206e 100644 --- a/codespell_lib/tests/test_basic.py +++ b/codespell_lib/tests/test_basic.py @@ -342,10 +342,10 @@ def test_exclude_file( bad_name = tmp_path / "bad.txt" # check all possible combinations of lines to ignore and ignores combinations = "".join( - "%(n)s abandonned %(n)s\n" - "%(n)s abandonned %(n)s\r\n" - "%(n)s abandonned %(n)s \n" - "%(n)s abandonned %(n)s \r\n" % {"n": n} + f"{n} abandonned {n}\n" + f"{n} abandonned {n}\r\n" + f"{n} abandonned {n} \n" + f"{n} abandonned {n} \r\n" for n in range(1, 5) ) bad_name.write_bytes(