diff --git a/nomenclature/codelist.py b/nomenclature/codelist.py index 1233a2a4..712481e9 100644 --- a/nomenclature/codelist.py +++ b/nomenclature/codelist.py @@ -390,7 +390,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: @@ -681,7 +681,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) diff --git a/nomenclature/config.py b/nomenclature/config.py index 0bae16b8..b5a59b7a 100644 --- a/nomenclature/config.py +++ b/nomenclature/config.py @@ -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( diff --git a/nomenclature/processor/data_validator.py b/nomenclature/processor/data_validator.py index 17b9624f..c0731aac 100644 --- a/nomenclature/processor/data_validator.py +++ b/nomenclature/processor/data_validator.py @@ -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) diff --git a/nomenclature/processor/region.py b/nomenclature/processor/region.py index a2da27ba..ce7ba43d 100644 --- a/nomenclature/processor/region.py +++ b/nomenclature/processor/region.py @@ -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 @@ -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) diff --git a/nomenclature/processor/required_data.py b/nomenclature/processor/required_data.py index 65643bd9..76d124c2 100644 --- a/nomenclature/processor/required_data.py +++ b/nomenclature/processor/required_data.py @@ -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) diff --git a/tests/test_definition.py b/tests/test_definition.py index 5243c64d..8700738f 100644 --- a/tests/test_definition.py +++ b/tests/test_definition.py @@ -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 diff --git a/tests/test_model_registration_parser.py b/tests/test_model_registration_parser.py index b446f740..c9142525 100644 --- a/tests/test_model_registration_parser.py +++ b/tests/test_model_registration_parser.py @@ -15,7 +15,8 @@ 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 @@ -23,12 +24,14 @@ def test_parse_model_registration(tmp_path): / "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"]}