Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added explicit encoding to all open statements. #407

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions nomenclature/codelist.py
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ def increase_indent(self, flow: bool = False, indentless: bool = False):

if path is None:
return stream
with open(path, "w") as file:
with open(path, "w", encoding="utf-8") as file:
file.write(stream)

def to_pandas(self, sort_by_code: bool = False) -> pd.DataFrame:
Expand Down Expand Up @@ -664,7 +664,7 @@ def list_missing_variables(
},
).to_yaml()

with open(file, "a") as f:
with open(file, "a", encoding="utf-8") as f:
f.write(missing_variables_formatted)


Expand Down
2 changes: 1 addition & 1 deletion nomenclature/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def fetch_repo(self, to_path):
def check_external_repo_double_stacking(self):
nomenclature_config = self.local_path / "nomenclature.yaml"
if nomenclature_config.is_file():
with open(nomenclature_config, "r") as f:
with open(nomenclature_config, "r", encoding="utf-8") as f:
config = yaml.safe_load(f)
if config.get("repositories"):
raise ValueError(
Expand Down
2 changes: 1 addition & 1 deletion nomenclature/processor/data_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def check_criteria(cls, v):

@classmethod
def from_file(cls, file: Union[Path, str]) -> "DataValidator":
with open(file, "r") as f:
with open(file, "r", encoding="utf-8") as f:
content = yaml.safe_load(f)
return cls(file=file, criteria_items=content)

Expand Down
4 changes: 2 additions & 2 deletions nomenclature/processor/region.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ def from_file(cls, file: Union[Path, str]):
@classmethod
def from_yaml(cls, file: Path) -> "RegionAggregationMapping":
try:
with open(file, "r") as f:
with open(file, "r", encoding="utf-8") as f:
mapping_input = yaml.safe_load(f)

# Add the file name to mapping_input
Expand Down Expand Up @@ -425,7 +425,7 @@ def to_yaml(self, file) -> None:
]
if self.exclude_regions:
dict_representation["exclude_regions"] = self.exclude_regions
with open(file, "w") as f:
with open(file, "w", encoding="utf-8") as f:
yaml.dump(dict_representation, f, sort_keys=False)


Expand Down
2 changes: 1 addition & 1 deletion nomenclature/processor/required_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ def convert_to_list(cls, v):

@classmethod
def from_file(cls, file: Union[Path, str]) -> "RequiredDataValidator":
with open(file, "r") as f:
with open(file, "r", encoding="utf-8") as f:
content = yaml.safe_load(f)
return cls(file=file, **content)

Expand Down
5 changes: 3 additions & 2 deletions tests/test_definition.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,10 @@ def test_create_yaml_from_xlsx(input_file, attrs, exp_file, tmpdir):
attrs=attrs,
)

with open(file, "r") as f:
with open(file, "r", encoding="utf-8") as f:
obs = f.read()
with open(TEST_DATA_DIR / "io" / "excel_io" / exp_file, "r") as f:
with open(TEST_DATA_DIR / "io" / "excel_io" / exp_file, "r",
encoding="utf-8") as f:
exp = f.read()

assert obs == exp
Expand Down
7 changes: 5 additions & 2 deletions tests/test_model_registration_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,23 @@ def test_parse_model_registration(tmp_path):
)

# Test model mapping
with open(tmp_path / "Model 1.1_mapping.yaml", "r") as file:
with open(tmp_path / "Model 1.1_mapping.yaml", "r", encoding="utf-8") \
as file:
obs_model_mapping = yaml.safe_load(file)
with open(
TEST_DATA_DIR
/ "region_processing"
/ "region_aggregation"
/ "excel_mapping_reference.yaml",
"r",
encoding="utf-8",
) as file:
exp_model_mapping = yaml.safe_load(file)
assert obs_model_mapping == exp_model_mapping

# Test model regions
with open(tmp_path / "Model 1.1_regions.yaml", "r") as file:
with open(tmp_path / "Model 1.1_regions.yaml", "r", encoding="utf-8") \
as file:
obs_model_regions = yaml.safe_load(file)
exp_model_regions = [
{"Model 1.1": ["Model 1.1|Region 1", "Region 2", "Model 1.1|Region 3"]}
Expand Down