Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jupytext refuses to open a non-unicode file (api, cli & jupyter) #897

Merged
merged 2 commits into from
Dec 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
Jupytext ChangeLog
==================

1.13.5 (2021-12-27)
-------------------

**Fixed**
- Jupytext refuses to open a text notebook that is not UTF-8 ([#896](https://github.com/mwouts/jupytext/issues/896))


1.13.4 (2021-12-12)
-------------------

Expand Down
2 changes: 1 addition & 1 deletion jupytext/contentsmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ def get(
if ext == ".ipynb":
model = self.super.get(path, content, type="notebook", format=format)
else:
model = self.super.get(path, content, type="file", format=format)
model = self.super.get(path, content, type="file", format="text")
model["type"] = "notebook"
if content:
# We may need to update these keys, inherited from text files formats
Expand Down
2 changes: 1 addition & 1 deletion jupytext/version.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
"""Jupytext's version number"""

__version__ = "1.13.4"
__version__ = "1.13.5"
14 changes: 14 additions & 0 deletions tests/invalid_file_896.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
jupytext:
formats: ipynb,md:myst
text_representation:
extension: .md
format_name: myst
format_version: 0.13
jupytext_version: 1.11.5
kernelspec:
display_name: Python 3 (ipykernel)
language: python
name: python3
---
Et voil�!
36 changes: 36 additions & 0 deletions tests/test_invalid_file.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
"""Jupytext should refuse to open a file with invalid content"""

from pathlib import Path

import pytest
from tornado.web import HTTPError

from jupytext import TextFileContentsManager, read
from jupytext.cli import jupytext as jupytext_cli

from .utils import skip_on_windows


@pytest.fixture
def invalid_md_file():
return Path(__file__).parent / "invalid_file_896.md"


@skip_on_windows
def test_read_invalid_md_file_fails(invalid_md_file):
with open(invalid_md_file) as fp:
with pytest.raises(UnicodeDecodeError):
read(fp)


def test_convert_invalid_md_file_fails(invalid_md_file):
with pytest.raises(UnicodeDecodeError):
jupytext_cli(["--to", "ipynb", str(invalid_md_file)])


def test_open_invalid_md_file_fails(invalid_md_file, tmp_path):
cm = TextFileContentsManager()
cm.root_dir = str(invalid_md_file.parent)

with pytest.raises(HTTPError, match="invalid_file_896.md is not UTF-8 encoded"):
cm.get(invalid_md_file.name)