Skip to content

Commit

Permalink
feat: add encoding to open module
Browse files Browse the repository at this point in the history
  • Loading branch information
Lucs1590 committed Apr 11, 2024
1 parent 83a91a6 commit 4899bfe
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
8 changes: 4 additions & 4 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()


Expand All @@ -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)


Expand All @@ -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(
Expand Down
4 changes: 2 additions & 2 deletions tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 4899bfe

Please sign in to comment.