diff --git a/nbformat/sign.py b/nbformat/sign.py index edb2c42b..572e10fc 100644 --- a/nbformat/sign.py +++ b/nbformat/sign.py @@ -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) diff --git a/nbformat/validator.py b/nbformat/validator.py index d578eb18..f72fbbcb 100644 --- a/nbformat/validator.py +++ b/nbformat/validator.py @@ -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 diff --git a/pyproject.toml b/pyproject.toml index 6ed30ff0..ac5c0140 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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] diff --git a/tests/test_sign.py b/tests/test_sign.py index 59724eb8..97d8ad8f 100644 --- a/tests/test_sign.py +++ b/tests/test_sign.py @@ -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( diff --git a/tests/v4/test_json.py b/tests/v4/test_json.py index 30c1eec6..21c7f9e9 100644 --- a/tests/v4/test_json.py +++ b/tests/v4/test_json.py @@ -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( @@ -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