Skip to content

Commit 80dd726

Browse files
authored
Fix encoding warnings (#371)
1 parent 27c896b commit 80dd726

File tree

5 files changed

+11
-6
lines changed

5 files changed

+11
-6
lines changed

nbformat/sign.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -602,7 +602,7 @@ def sign_notebook_file(self, notebook_path):
602602
if not os.path.exists(notebook_path):
603603
self.log.error("Notebook missing: %s" % notebook_path)
604604
self.exit(1)
605-
with open(notebook_path, encoding="utf8") as f:
605+
with open(notebook_path, encoding="utf-8") as f:
606606
nb = read(f, NO_CONVERT)
607607
self.sign_notebook(nb, notebook_path)
608608

nbformat/validator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ def _get_schema_json(v, version=None, version_minor=None):
9999
else:
100100
msg = "Cannot find appropriate nbformat schema file."
101101
raise AttributeError(msg)
102-
with open(schema_path) as f:
102+
with open(schema_path, encoding='utf-8') as f:
103103
schema_json = json.load(f)
104104
return schema_json
105105

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ build = "make -C docs html SPHINXOPTS='-W'"
6969
[tool.hatch.envs.test]
7070
features = ["test"]
7171
[tool.hatch.envs.test.scripts]
72-
test = "python -m pytest -vv {args}"
72+
test = "PYTHONWARNDEFAULTENCODING=1 python -m pytest -vv {args}"
7373
nowarn = "test -W default {args}"
7474

7575
[tool.hatch.envs.cov]

tests/test_sign.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def tearDown(self):
4040

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

4646
invalid_notary = sign.NotebookNotary(

tests/v4/test_json.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,9 @@ def test_latest_schema_matches(self):
108108

109109
def test_base_version_matches_latest(self):
110110
"""Test to ensure latest version file matches latest verison"""
111-
with open(os.path.join(BASE_PATH, "nbformat.v4.schema.json")) as schema_file:
111+
with open(
112+
os.path.join(BASE_PATH, "nbformat.v4.schema.json"), encoding='utf-8'
113+
) as schema_file:
112114
latest_schema = json.load(schema_file)
113115
with open(
114116
os.path.join(
@@ -117,13 +119,16 @@ def test_base_version_matches_latest(self):
117119
major=nbformat, minor=nbformat_minor
118120
),
119121
),
122+
encoding='utf-8',
120123
) as schema_file: # noqa
121124
ver_schema = json.load(schema_file)
122125
assert latest_schema == ver_schema
123126

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

0 commit comments

Comments
 (0)