Skip to content

Commit

Permalink
Fix encoding warnings (#371)
Browse files Browse the repository at this point in the history
  • Loading branch information
blink1073 authored Jul 30, 2023
1 parent 27c896b commit 80dd726
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 6 deletions.
2 changes: 1 addition & 1 deletion nbformat/sign.py
Original file line number Diff line number Diff line change
Expand Up @@ -602,7 +602,7 @@ def sign_notebook_file(self, notebook_path):
if not os.path.exists(notebook_path):
self.log.error("Notebook missing: %s" % notebook_path)
self.exit(1)
with open(notebook_path, encoding="utf8") as f:
with open(notebook_path, encoding="utf-8") as f:
nb = read(f, NO_CONVERT)
self.sign_notebook(nb, notebook_path)

Expand Down
2 changes: 1 addition & 1 deletion nbformat/validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def _get_schema_json(v, version=None, version_minor=None):
else:
msg = "Cannot find appropriate nbformat schema file."
raise AttributeError(msg)
with open(schema_path) as f:
with open(schema_path, encoding='utf-8') as f:
schema_json = json.load(f)
return schema_json

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ build = "make -C docs html SPHINXOPTS='-W'"
[tool.hatch.envs.test]
features = ["test"]
[tool.hatch.envs.test.scripts]
test = "python -m pytest -vv {args}"
test = "PYTHONWARNDEFAULTENCODING=1 python -m pytest -vv {args}"
nowarn = "test -W default {args}"

[tool.hatch.envs.cov]
Expand Down
2 changes: 1 addition & 1 deletion tests/test_sign.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def tearDown(self):

def test_invalid_db_file(self):
invalid_sql_file = os.path.join(self.data_dir, "invalid_db_file.db")
with open(invalid_sql_file, "w") as tempfile:
with open(invalid_sql_file, "w", encoding="utf-8") as tempfile:
tempfile.write("[invalid data]")

invalid_notary = sign.NotebookNotary(
Expand Down
9 changes: 7 additions & 2 deletions tests/v4/test_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,9 @@ def test_latest_schema_matches(self):

def test_base_version_matches_latest(self):
"""Test to ensure latest version file matches latest verison"""
with open(os.path.join(BASE_PATH, "nbformat.v4.schema.json")) as schema_file:
with open(
os.path.join(BASE_PATH, "nbformat.v4.schema.json"), encoding='utf-8'
) as schema_file:
latest_schema = json.load(schema_file)
with open(
os.path.join(
Expand All @@ -117,13 +119,16 @@ def test_base_version_matches_latest(self):
major=nbformat, minor=nbformat_minor
),
),
encoding='utf-8',
) as schema_file: # noqa
ver_schema = json.load(schema_file)
assert latest_schema == ver_schema

def test_latest_matches_nbformat(self):
"""Test to ensure that the nbformat version matches the description of the latest schema"""
with open(os.path.join(BASE_PATH, "nbformat.v4.schema.json")) as schema_file:
with open(
os.path.join(BASE_PATH, "nbformat.v4.schema.json"), encoding='utf-8'
) as schema_file:
schema = json.load(schema_file)
assert schema["description"] == "Jupyter Notebook v{major}.{minor} JSON schema.".format(
major=nbformat, minor=nbformat_minor
Expand Down

0 comments on commit 80dd726

Please sign in to comment.