From 354918f3718353765beea6b9a06f8be6ebc6b71f Mon Sep 17 00:00:00 2001 From: Sean Budd Date: Mon, 23 Sep 2024 16:37:48 +1000 Subject: [PATCH] Use utf-8 for validation (#40) --- _tests/test_createJson.py | 6 +++--- _tests/test_validate.py | 4 ++-- _validate/createJson.py | 2 +- _validate/regenerateTranslations.py | 4 ++-- _validate/validate.py | 8 ++++---- 5 files changed, 12 insertions(+), 12 deletions(-) diff --git a/_tests/test_createJson.py b/_tests/test_createJson.py index 6b793d4..c8d2226 100644 --- a/_tests/test_createJson.py +++ b/_tests/test_createJson.py @@ -32,7 +32,7 @@ def getAddonManifest(): - with open(MANIFEST_FILE) as f: + with open(MANIFEST_FILE, encoding="utf-8") as f: manifest = addonManifest.AddonManifest(f) return manifest @@ -74,10 +74,10 @@ def test_contentsMatchesExampleFile(self): def _assertJsonFilesEqual(self, actualJsonPath: str, expectedJsonPath: str): # Not equal, how are they different? - with open(VALID_JSON) as expectedFile: + with open(VALID_JSON, encoding="utf-8") as expectedFile: expectedJson = json.load(expectedFile) del expectedJson["sha256-comment"] # remove explanatory comment - with open(actualJsonPath) as actualFile: + with open(actualJsonPath, encoding="utf-8") as actualFile: actualJson = json.load(actualFile) del actualJson["submissionTime"] # remove submission time diff --git a/_tests/test_validate.py b/_tests/test_validate.py index ce175e4..851597d 100644 --- a/_tests/test_validate.py +++ b/_tests/test_validate.py @@ -26,13 +26,13 @@ def getValidAddonSubmission() -> validate.JsonObjT: - with open(VALID_SUBMISSION_JSON_FILE) as f: + with open(VALID_SUBMISSION_JSON_FILE, encoding="utf-8") as f: submission = json.load(f) return submission def getAddonManifest(): - with open(MANIFEST_FILE) as f: + with open(MANIFEST_FILE, encoding="utf-8") as f: manifest = addonManifest.AddonManifest(f) return manifest diff --git a/_validate/createJson.py b/_validate/createJson.py index d9112f1..a135071 100644 --- a/_validate/createJson.py +++ b/_validate/createJson.py @@ -61,7 +61,7 @@ def generateJsonFile( filePath = buildOutputFilePath(data, parentDir) - with open(filePath, "wt") as f: + with open(filePath, "wt", encoding="utf-8") as f: json.dump(data, f, indent="\t") print(f"Wrote json file: {filePath}") diff --git a/_validate/regenerateTranslations.py b/_validate/regenerateTranslations.py index 3de8005..5a3a8c1 100644 --- a/_validate/regenerateTranslations.py +++ b/_validate/regenerateTranslations.py @@ -22,7 +22,7 @@ def regenerateJsonFile(filePath: str, errorFilePath: Optional[str]) -> None: - with open(filePath) as f: + with open(filePath, encoding="utf-8") as f: addonData = json.load(f) if addonData.get("legacy"): return @@ -44,7 +44,7 @@ def regenerateJsonFile(filePath: str, errorFilePath: Optional[str]) -> None: } ) - with open(filePath, "wt") as f: + with open(filePath, "wt", encoding="utf-8") as f: json.dump(addonData, f, indent="\t") print(f"Wrote json file: {filePath}") diff --git a/_validate/validate.py b/_validate/validate.py index efc3e98..ae756d0 100644 --- a/_validate/validate.py +++ b/_validate/validate.py @@ -42,7 +42,7 @@ def getAddonMetadata(filename: str) -> JsonObjT: """Loads addon submission metadata json file and returns as object. Raises if the metadata does not conform to the schema. """ - with open(filename) as f: + with open(filename, encoding="utf-8") as f: data: JsonObjT = json.load(f) _validateJson(data) return data @@ -51,7 +51,7 @@ def getAddonMetadata(filename: str) -> JsonObjT: def getExistingVersions(verFilename: str) -> List[str]: """Loads API versions file and returns list of versions formatted as strings. """ - with open(verFilename) as f: + with open(verFilename, encoding="utf-8") as f: data: List[JsonObjT] = json.load(f) return [_formatVersionString(version["apiVer"].values()) for version in data] @@ -59,7 +59,7 @@ def getExistingVersions(verFilename: str) -> List[str]: def getExistingStableVersions(verFilename: str) -> List[str]: """Loads API versions file and returns list of stable versions formatted as strings. """ - with open(verFilename) as f: + with open(verFilename, encoding="utf-8") as f: data: List[JsonObjT] = json.load(f) return [ _formatVersionString(version["apiVer"].values()) @@ -72,7 +72,7 @@ def _validateJson(data: JsonObjT) -> None: """ Ensure that the loaded metadata conforms to the schema. Raise error if not """ - with open(JSON_SCHEMA) as f: + with open(JSON_SCHEMA, encoding="utf-8") as f: schema = json.load(f) try: validate(instance=data, schema=schema)