fix fileinput.input encoding only since Python 3.10

cv2_1
scito 1 year ago
parent 003e122808
commit 869c404489

@ -343,7 +343,11 @@ 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, encoding='utf-8')
# PYTHON >= 3.10 support encoding
if sys.version_info >= (3, 10):
finput = fileinput.input(filename, encoding='utf-8')
else:
finput = fileinput.input(filename)
try:
lines = []
for line in (line.strip() for line in finput):

@ -38,7 +38,7 @@ 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")
# @pytest.mark.skipif(sys.platform.startswith("win") or not qreader_available or sys.implementation.name == 'pypy' or sys.version_info >= (3, 10), reason="Quickfix")
def test_extract_stdout(capsys: pytest.CaptureFixture[str]) -> None:
@ -356,6 +356,7 @@ def test_normalize_bytes() -> None:
# Generate verbose output: python3.11 src/extract_otp_secrets.py example_export.txt -v -n > tests/data/print_verbose_output.txt
@pytest.mark.skipif(sys.version_info < (3, 10), reason="fileinput.input encoding exists since PYTHON 3.10")
def test_extract_verbose(capsys: pytest.CaptureFixture[str], relaxed: bool) -> None:
# Act
extract_otp_secrets.main(['-n', '-v', 'example_export.txt'])

Loading…
Cancel
Save