Skip to content

Commit

Permalink
Add utf-8 encoding when open files, #14
Browse files Browse the repository at this point in the history
This should fix the issue with broken tests
on Windows.
  • Loading branch information
ajwalkiewicz committed Nov 25, 2022
1 parent 88952b0 commit 6a2e4a2
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 5 deletions.
8 changes: 6 additions & 2 deletions cochar/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ def set_logging_level(logging_level=logging_level):
"damage_bonus": ["-2", "-1", "0", "+1K4", "+1K6", "+2K6", "+3K6", "+4K6", "+5K6"],
}

with open(os.path.join(_THIS_FOLDER, "data", "occupations.json"), "r") as json_file:
with open(
os.path.join(_THIS_FOLDER, "data", "occupations.json"), "r", encoding="utf-8"
) as json_file:
# Full data of occupations
OCCUPATIONS_DATA: Dict[str, dict] = dict(json.load(json_file))
# Just occupations names in the list
Expand All @@ -72,7 +74,9 @@ def set_logging_level(logging_level=logging_level):
[key for key, value in OCCUPATIONS_DATA.items() if "edustr" in value["groups"]],
]

with open(os.path.join(_THIS_FOLDER, "data", "settings.json"), "r") as json_file:
with open(
os.path.join(_THIS_FOLDER, "data", "settings.json"), "r", encoding="utf-8"
) as json_file:
settings: dict = json.load(json_file)
MIN_AGE: int = settings["min_age"]
MAX_AGE: int = settings["max_age"]
Expand Down
2 changes: 1 addition & 1 deletion cochar/cochar.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ def correct_bisect_left(data, year):

file_name = f"pop{corrected_year}"

with open(cochar.POP_PYRAMID_PATH) as json_file:
with open(cochar.POP_PYRAMID_PATH, "r", encoding="utf-8") as json_file:
age_population = cochar.utils.AGE_RANGE
age_weights = json.load(json_file)[file_name][sex][3:-1]
age_range = random.choices(age_population, weights=age_weights)[0]
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

THIS_FOLDER = os.path.dirname(os.path.abspath(__file__))

with open(f"{THIS_FOLDER}/docs/readme.md", "r") as fh:
with open(f"{THIS_FOLDER}/docs/readme.md", "r", encoding="utf-8") as fh:
long_description = fh.read()

setup(
Expand Down
2 changes: 1 addition & 1 deletion webapp/webapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
_THIS_FOLDER = os.path.dirname(os.path.abspath(__file__))
_README = os.path.abspath(os.path.join(_THIS_FOLDER, "static", "README.md"))

with open(_README, "r") as readme:
with open(_README, "r", encoding="utf-8") as readme:
text = readme.read()
html = markdown.markdown(text)

Expand Down

0 comments on commit 6a2e4a2

Please sign in to comment.