Skip to content

Commit 730a8f0

Browse files
committed
ISSUE-20: Print full path from no-boms
1 parent 748486c commit 730a8f0

File tree

2 files changed

+16
-16
lines changed

2 files changed

+16
-16
lines changed

hooks/no_boms.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import argparse
44
from collections.abc import Sequence
5-
from os.path import basename
65

76

87
def main(argv: Sequence[str] | None = None) -> int:
@@ -21,19 +20,19 @@ def main(argv: Sequence[str] | None = None) -> int:
2120
# Cf. https://www.unicode.org/faq/utf_bom.html#BOM
2221
if candidate == b'\xff\xfe\x00\x00':
2322
result *= 13
24-
print(f'{basename(filename)}: has a UTF-32 BOM (LE)')
23+
print(f'{filename}: has a UTF-32 BOM (LE)')
2524
elif candidate == b'\x00\x00\xfe\xff':
2625
result *= 11
27-
print(f'{basename(filename)}: has a UTF-32 BOM (BE)')
26+
print(f'{filename}: has a UTF-32 BOM (BE)')
2827
elif candidate[:2] == b'\xff\xfe':
2928
result *= 7
30-
print(f'{basename(filename)}: has a UTF-16 BOM (LE)')
29+
print(f'{filename}: has a UTF-16 BOM (LE)')
3130
elif candidate[:2] == b'\xfe\xff':
3231
result *= 5
33-
print(f'{basename(filename)}: has a UTF-16 BOM (BE)')
32+
print(f'{filename}: has a UTF-16 BOM (BE)')
3433
elif candidate[:3] == b'\xef\xbb\xbf':
3534
result *= 3
36-
print(f'{basename(filename)}: has a UTF-8 BOM')
35+
print(f'{filename}: has a UTF-8 BOM')
3736

3837
return result % 256 if result != 1 else 0
3938

tests/test_no_boms.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from __future__ import annotations
22

3+
import re
34
import unittest
45
from pathlib import Path
56
from unittest.mock import call
@@ -20,8 +21,8 @@ def test_utf32_bom_le(tmpdir):
2021
b'\x86\x98\xe3\x86\x92\xe3\x86\x9d',
2122
)
2223
assert no_boms.main((str(f),)) == 13
23-
assert call('bom32le.txt: has a UTF-32 BOM (LE)') \
24-
in mocked_print.mock_calls
24+
assert re.match(r'^.*[\\/]bom32le\.txt: has a UTF-32 BOM \(LE\)$',
25+
mocked_print.call_args.args[0]) is not None
2526

2627

2728
def test_utf32_bom_be(tmpdir):
@@ -37,8 +38,8 @@ def test_utf32_bom_be(tmpdir):
3738
b'\x86\x98\xe3\x86\x92\xe3\x86\x9d',
3839
)
3940
assert no_boms.main((str(f),)) == 11
40-
assert call('bom32be.txt: has a UTF-32 BOM (BE)') \
41-
in mocked_print.mock_calls
41+
assert re.match(r'^.*[\\/]bom32be\.txt: has a UTF-32 BOM \(BE\)$',
42+
mocked_print.call_args.args[0]) is not None
4243

4344

4445
def test_utf16_bom_le(tmpdir):
@@ -54,8 +55,8 @@ def test_utf16_bom_le(tmpdir):
5455
b'\x86\x98\xe3\x86\x92\xe3\x86\x9d',
5556
)
5657
assert no_boms.main((str(f),)) == 7
57-
assert call('bom16le.txt: has a UTF-16 BOM (LE)') \
58-
in mocked_print.mock_calls
58+
assert re.match(r'^.*[\\/]bom16le\.txt: has a UTF-16 BOM \(LE\)$',
59+
mocked_print.call_args.args[0]) is not None
5960

6061

6162
def test_utf16_bom_be(tmpdir):
@@ -71,8 +72,8 @@ def test_utf16_bom_be(tmpdir):
7172
b'\x86\x98\xe3\x86\x92\xe3\x86\x9d',
7273
)
7374
assert no_boms.main((str(f),)) == 5
74-
assert call('bom16be.txt: has a UTF-16 BOM (BE)') \
75-
in mocked_print.mock_calls
75+
assert re.match(r'^.*[\\/]bom16be\.txt: has a UTF-16 BOM \(BE\)$',
76+
mocked_print.call_args.args[0]) is not None
7677

7778

7879
def test_utf8_bom_directly(tmpdir):
@@ -88,8 +89,8 @@ def test_utf8_bom_directly(tmpdir):
8889
b'\x86\x98\xe3\x86\x92\xe3\x86\x9d',
8990
)
9091
assert no_boms.main((str(f),)) == 3
91-
assert call('bom8.txt: has a UTF-8 BOM') \
92-
in mocked_print.mock_calls
92+
assert re.match(r'^.*[\\/]bom8\.txt: has a UTF-8 BOM$',
93+
mocked_print.call_args.args[0]) is not None
9394

9495

9596
def test_utf8_bom_via_encoding(tmpdir):

0 commit comments

Comments
 (0)