From 5be6e9c322c47acdbcf89b08c93997e9e23124a5 Mon Sep 17 00:00:00 2001 From: scito Date: Sat, 31 Dec 2022 21:24:01 +0100 Subject: [PATCH] fix finput encoding problem on Windows --- src/extract_otp_secrets.py | 2 +- tests/extract_otp_secrets_test.py | 6 ++++-- tests/extract_otp_secrets_txt_unit_test.py | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/extract_otp_secrets.py b/src/extract_otp_secrets.py index 02125cd..7bcddaf 100644 --- a/src/extract_otp_secrets.py +++ b/src/extract_otp_secrets.py @@ -335,7 +335,7 @@ def get_otp_urls_from_file(filename: str, args: Args) -> OtpUrls: def read_lines_from_text_file(filename: str) -> list[str]: if verbose: print(f"Reading lines of {filename}") - finput = fileinput.input(filename) + finput = fileinput.input(filename, encoding='utf-8') try: lines = [] for line in (line.strip() for line in finput): diff --git a/tests/extract_otp_secrets_test.py b/tests/extract_otp_secrets_test.py index 505b606..c7d473c 100644 --- a/tests/extract_otp_secrets_test.py +++ b/tests/extract_otp_secrets_test.py @@ -36,6 +36,10 @@ from utils import (file_exits, quick_and_dirty_workaround_encoding_problem, qreader_available: bool = extract_otp_secrets.qreader_available +# Quickfix comment +#@pytest.mark.skipif(sys.platform.startswith("win") or not qreader_available or sys.implementation.name == 'pypy', reason="Quickfix") + + def test_extract_stdout(capsys: pytest.CaptureFixture[str]) -> None: # Act extract_otp_secrets.main(['example_export.txt']) @@ -91,7 +95,6 @@ def test_extract_stdin_empty(capsys: pytest.CaptureFixture[str], monkeypatch: py assert captured.err == 'WARN: stdin is empty\n' -# @pytest.mark.skipif(not qreader_available, reason='Test if cv2 and qreader are not available.') def test_extract_empty_file_no_qreader(capsys: pytest.CaptureFixture[str]) -> None: if qreader_available: # Act @@ -351,7 +354,6 @@ def test_normalize_bytes() -> None: 'Before\\\\302\\\\277\\\\303\nname: enc: \\302\\277\\303\\244\\303\\204\\303\\251\\303\\211?\nAfter') == 'Before\\\\302\\\\277\\\\303\nname: enc: ¿äÄéÉ?\nAfter' -@pytest.mark.skipif(sys.platform.startswith("win"), reason="Avoid encoding problems") def test_extract_verbose(capsys: pytest.CaptureFixture[str], relaxed: bool) -> None: # Act extract_otp_secrets.main(['-v', 'example_export.txt']) diff --git a/tests/extract_otp_secrets_txt_unit_test.py b/tests/extract_otp_secrets_txt_unit_test.py index 6e1c19b..c6fb84a 100644 --- a/tests/extract_otp_secrets_txt_unit_test.py +++ b/tests/extract_otp_secrets_txt_unit_test.py @@ -171,7 +171,7 @@ Type: totp self.assertEqual(count_files_in_dir('testout/qr'), 6) def test_extract_verbose(self) -> None: - if sys.implementation.name == 'pypy' or sys.platform.startswith("win"): + if sys.implementation.name == 'pypy': self.skipTest("Avoid encoding problems") out = io.StringIO() with redirect_stdout(out):