From 4899bfe643ab1d723d0814520876dcb2fd6c940b Mon Sep 17 00:00:00 2001 From: Lucas Brito Date: Thu, 11 Apr 2024 17:25:42 -0300 Subject: [PATCH] feat: add encoding to open module --- src/main.py | 8 ++++---- tests/test_main.py | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main.py b/src/main.py index 81be140..325714c 100644 --- a/src/main.py +++ b/src/main.py @@ -98,7 +98,7 @@ def format_to_swim(file_path: str) -> None: def read_xml_file(file_path: str) -> str: - with open(file_path, "r") as xml_file: + with open(file_path, "r", encoding='utf-8') as xml_file: return xml_file.read() @@ -110,7 +110,7 @@ def modify_xml_header(xml_str: str) -> str: def write_xml_file(file_path: str, xml_str: str) -> None: - with open(file_path, "w") as xml_file: + with open(file_path, "w", encoding='utf-8') as xml_file: xml_file.write(xml_str) @@ -135,12 +135,12 @@ def validate_tcx_file(file_path: str) -> bool: def indent_xml_file(file_path: str) -> None: try: - with open(file_path, "r") as xml_file: + with open(file_path, "r", encoding='utf-8') as xml_file: xml_content = xml_file.read() xml_dom = parseString(xml_content) - with open(file_path, "w") as xml_file: + with open(file_path, "w", encoding='utf-8') as xml_file: xml_file.write(xml_dom.toprettyxml(indent=" ")) except Exception as err: logger.warning( diff --git a/tests/test_main.py b/tests/test_main.py index 8fe065f..524fbd9 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -61,7 +61,7 @@ def test_write_xml_file(self): write_xml_file(file_path, xml_str) - with open(file_path, "r") as xml_file: + with open(file_path, "r", encoding='utf-8') as xml_file: content = xml_file.read() self.assertEqual(content, xml_str) @@ -97,7 +97,7 @@ def test_indent_xml_file(self): file_path = "assets/test.xml" indent_xml_file(file_path) - with open(file_path, "r") as xml_file: + with open(file_path, "r", encoding='utf-8') as xml_file: content = xml_file.read() self.assertIn(