Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 Fix CLI when using --minimal output in certain cases #103

Merged
merged 2 commits into from
Sep 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions charset_normalizer/cli/normalizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ def cli_detect(argv: List[str] = None) -> int:

if len(matches) > 1 and args.alternatives:
for el in matches:
if el != matches:
if el != best_guess:
x_.append(
CliDetectionResult(
abspath(my_file.name),
Expand Down Expand Up @@ -273,7 +273,16 @@ def cli_detect(argv: List[str] = None) -> int:
)
)
else:
print(", ".join([el.encoding if el.encoding else "undefined" for el in x_]))
for my_file in args.files:
print(
", ".join(
[
el.encoding if el.encoding else "undefined"
for el in x_
if el.path == abspath(my_file.name)
]
)
)

return 0

Expand Down
40 changes: 40 additions & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,46 @@ def test_multiple_file(self):
)
)

def test_with_alternative(self):
self.assertEqual(
0,
cli_detect(
[
'-a',
'./data/sample.1.ar.srt',
'./data/sample.1.he.srt',
'./data/sample-chinese.txt'
]
)
)

def test_with_minimal_output(self):
self.assertEqual(
0,
cli_detect(
[
'-m',
'./data/sample.1.ar.srt',
'./data/sample.1.he.srt',
'./data/sample-chinese.txt'
]
)
)

def test_with_minimal_and_alt(self):
self.assertEqual(
0,
cli_detect(
[
'-m',
'-a',
'./data/sample.1.ar.srt',
'./data/sample.1.he.srt',
'./data/sample-chinese.txt'
]
)
)

def test_non_existent_file(self):

with self.assertRaises(SystemExit) as cm:
Expand Down