Skip to content

Commit

Permalink
Assert text files are in utf8 (#350)
Browse files Browse the repository at this point in the history
Read and write text files with utf8 encoding.

Signed-off-by: Bobby Noelte <[email protected]>
  • Loading branch information
b0661 authored Jan 7, 2025
1 parent ef60f5b commit d2f6e98
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 14 deletions.
4 changes: 2 additions & 2 deletions scripts/extract_markdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ def main():

try:
if args.input_file:
with open(args.input_file, "r") as f:
with open(args.input_file, "r", encoding="utf8") as f:
content = f.read()
elif args.input:
content = args.input
Expand All @@ -164,7 +164,7 @@ def main():
)
if args.output_file:
# Write to file
with open(args.output_file, "w") as f:
with open(args.output_file, "w", encoding="utf8") as f:
f.write(extracted_content)
else:
# Write to std output
Expand Down
2 changes: 1 addition & 1 deletion scripts/generate_config_md.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ def main():
config_md = generate_config_md()
if args.output_file:
# Write to file
with open(args.output_file, "w") as f:
with open(args.output_file, "w", encoding="utf8") as f:
f.write(config_md)
else:
# Write to std output
Expand Down
2 changes: 1 addition & 1 deletion scripts/generate_openapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def main():
openapi_spec_str = json.dumps(openapi_spec, indent=2)
if args.output_file:
# Write to file
with open(args.output_file, "w") as f:
with open(args.output_file, "w", encoding="utf8") as f:
f.write(openapi_spec_str)
else:
# Write to std output
Expand Down
2 changes: 1 addition & 1 deletion scripts/generate_openapi_md.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ def main():
openapi_md = generate_openapi_md()
if args.output_file:
# Write to file
with open(args.output_file, "w") as f:
with open(args.output_file, "w", encoding="utf8") as f:
f.write(openapi_md)
else:
# Write to std output
Expand Down
8 changes: 4 additions & 4 deletions tests/test_doc.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def test_openapi_md_current(config_eos):
expected_spec_md_path = DIR_PROJECT_ROOT / "docs" / "_generated" / "openapi.md"
new_spec_md_path = DIR_TESTDATA / "openapi-new.md"

with open(expected_spec_md_path) as f_expected:
with open(expected_spec_md_path, encoding="utf8") as f_expected:
expected_spec_md = f_expected.read()

# Patch get_config and import within guard to patch global variables within the fastapi_server module.
Expand All @@ -59,7 +59,7 @@ def test_openapi_md_current(config_eos):

spec_md = generate_openapi_md.generate_openapi_md()

with open(new_spec_md_path, "w") as f_new:
with open(new_spec_md_path, "w", encoding="utf8") as f_new:
f_new.write(spec_md)

try:
Expand All @@ -76,7 +76,7 @@ def test_config_md_current(config_eos):
expected_config_md_path = DIR_PROJECT_ROOT / "docs" / "_generated" / "config.md"
new_config_md_path = DIR_TESTDATA / "config-new.md"

with open(expected_config_md_path) as f_expected:
with open(expected_config_md_path, encoding="utf8") as f_expected:
expected_config_md = f_expected.read()

# Patch get_config and import within guard to patch global variables within the fastapi_server module.
Expand All @@ -88,7 +88,7 @@ def test_config_md_current(config_eos):

config_md = generate_config_md.generate_config_md()

with open(new_config_md_path, "w") as f_new:
with open(new_config_md_path, "w", encoding="utf8") as f_new:
f_new.write(config_md)

try:
Expand Down
6 changes: 3 additions & 3 deletions tests/test_pvforecastakkudoktor.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,23 +61,23 @@ def sample_settings(config_eos):
@pytest.fixture
def sample_forecast_data():
"""Fixture that returns sample forecast data converted to pydantic model."""
with open(FILE_TESTDATA_PV_FORECAST_INPUT_1, "r") as f_in:
with open(FILE_TESTDATA_PV_FORECAST_INPUT_1, "r", encoding="utf8") as f_in:
input_data = f_in.read()
return PVForecastAkkudoktor._validate_data(input_data)


@pytest.fixture
def sample_forecast_data_raw():
"""Fixture that returns raw sample forecast data."""
with open(FILE_TESTDATA_PV_FORECAST_INPUT_1, "r") as f_in:
with open(FILE_TESTDATA_PV_FORECAST_INPUT_1, "r", encoding="utf8") as f_in:
input_data = f_in.read()
return input_data


@pytest.fixture
def sample_forecast_report():
"""Fixture that returns sample forecast data report."""
with open(FILE_TESTDATA_PV_FORECAST_RESULT_1, "r") as f_res:
with open(FILE_TESTDATA_PV_FORECAST_RESULT_1, "r", encoding="utf8") as f_res:
input_data = f_res.read()
return input_data

Expand Down
4 changes: 2 additions & 2 deletions tests/test_weatherclearoutside.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def sample_clearout_1_html():
@pytest.fixture
def sample_clearout_1_data():
"""Fixture that returns sample forecast data."""
with open(FILE_TESTDATA_WEATHERCLEAROUTSIDE_1_DATA, "r") as f_in:
with open(FILE_TESTDATA_WEATHERCLEAROUTSIDE_1_DATA, "r", encoding="utf8") as f_in:
json_str = f_in.read()
data = WeatherClearOutside.from_json(json_str)
return data
Expand Down Expand Up @@ -212,7 +212,7 @@ def test_development_forecast_data(mock_get, weather_provider, sample_clearout_1
# Fill the instance
weather_provider.update_data(force_enable=True)

with open(FILE_TESTDATA_WEATHERCLEAROUTSIDE_1_DATA, "w") as f_out:
with open(FILE_TESTDATA_WEATHERCLEAROUTSIDE_1_DATA, "w", encoding="utf8") as f_out:
f_out.write(weather_provider.to_json())


Expand Down

0 comments on commit d2f6e98

Please sign in to comment.