From a51507b7011375d861a60f2afe7753caf1578c3e Mon Sep 17 00:00:00 2001 From: u231053 Date: Mon, 19 Dec 2022 16:39:28 +0100 Subject: [PATCH] fix #30: enforce utf-8 encoding since windows used non-utf8-encoding --- extract_otp_secret_keys.py | 4 ++-- test_extract_otp_secret_keys_pytest.py | 2 +- test_extract_otp_secret_keys_unittest.py | 1 - utils.py | 6 +++--- 4 files changed, 6 insertions(+), 7 deletions(-) diff --git a/extract_otp_secret_keys.py b/extract_otp_secret_keys.py index 3f448ca..7c152d4 100644 --- a/extract_otp_secret_keys.py +++ b/extract_otp_secret_keys.py @@ -305,7 +305,7 @@ def open_file_or_stdout(filename): '''stdout is denoted as "-". Note: Set before the following line: sys.stdout.close = lambda: None''' - return open(filename, "w") if filename != '-' else sys.stdout + return open(filename, "w", encoding='utf-8') if filename != '-' else sys.stdout def open_file_or_stdout_for_csv(filename): @@ -313,7 +313,7 @@ def open_file_or_stdout_for_csv(filename): newline='' Note: Set before the following line: sys.stdout.close = lambda: None''' - return open(filename, "w", newline='') if filename != '-' else sys.stdout + return open(filename, "w", encoding='utf-8', newline='') if filename != '-' else sys.stdout def eprint(*args, **kwargs): diff --git a/test_extract_otp_secret_keys_pytest.py b/test_extract_otp_secret_keys_pytest.py index 4b308b8..99b1951 100644 --- a/test_extract_otp_secret_keys_pytest.py +++ b/test_extract_otp_secret_keys_pytest.py @@ -270,7 +270,7 @@ Type: totp assert captured.out == expected_stdout assert captured.err == '' -@mark.skipif(platform.startswith("win"), reason="This test is not supported on Windows.") + def test_extract_printqr(capsys): # Act extract_otp_secret_keys.main(['-p', 'example_export.txt']) diff --git a/test_extract_otp_secret_keys_unittest.py b/test_extract_otp_secret_keys_unittest.py index da294c4..e4839b7 100644 --- a/test_extract_otp_secret_keys_unittest.py +++ b/test_extract_otp_secret_keys_unittest.py @@ -140,7 +140,6 @@ Type: totp self.assertEqual(actual_output, expected_output) def test_extract_printqr(self): - if platform.startswith("win"): self.skipTest("This test is not supported on Windows.") out = io.StringIO() with redirect_stdout(out): extract_otp_secret_keys.main(['-p', 'example_export.txt']) diff --git a/utils.py b/utils.py index 565ee25..3fae164 100644 --- a/utils.py +++ b/utils.py @@ -59,7 +59,7 @@ def remove_dir_with_files(dir): def read_csv(filename): """Returns a list of lines.""" - with open(filename, "r", newline='') as infile: + with open(filename, "r", encoding="utf-8", newline='') as infile: lines = [] reader = csv.reader(infile) for line in reader: @@ -78,7 +78,7 @@ def read_csv_str(str): def read_json(filename): """Returns a list or a dictionary.""" - with open(filename, "r") as infile: + with open(filename, "r", encoding="utf-8") as infile: return json.load(infile) @@ -89,7 +89,7 @@ def read_json_str(str): def read_file_to_list(filename): """Returns a list of lines.""" - with open(filename, "r") as infile: + with open(filename, "r", encoding="utf-8") as infile: return infile.readlines()