Ejemplo n.º 1
0
def test_metadata_and_cell_to_header2(no_jupytext_version_number):
    nb = new_notebook(cells=[new_markdown_cell(source="Some markdown\ntext")])
    header, lines_to_next_cell = metadata_and_cell_to_header(
        nb, {}, get_format_implementation(".md"), ".md")
    assert header == []
    assert len(nb.cells) == 1
    assert lines_to_next_cell is None
Ejemplo n.º 2
0
def test_metadata_and_cell_to_header2():
    nb = new_notebook(cells=[new_markdown_cell(source="Some markdown\ntext")])
    with mock.patch('jupytext.header.INSERT_AND_CHECK_VERSION_NUMBER', False):
        header, lines_to_next_cell = metadata_and_cell_to_header(nb, {}, get_format_implementation('.md'), '.md')
    assert header == []
    assert len(nb.cells) == 1
    assert lines_to_next_cell is None
Ejemplo n.º 3
0
def test_metadata_and_cell_to_header(no_jupytext_version_number):
    metadata = {'jupytext': {'mainlanguage': 'python'}}
    nb = new_notebook(
        metadata=metadata,
        cells=[new_raw_cell(source="---\ntitle: Sample header\n---")])
    header, lines_to_next_cell = metadata_and_cell_to_header(nb, metadata, get_format_implementation('.md'), '.md')
    assert '\n'.join(header) == """---
title: Sample header
jupyter:
  jupytext:
    mainlanguage: python
---"""
    assert nb.cells == []
    assert lines_to_next_cell is None
Ejemplo n.º 4
0
def test_metadata_and_cell_to_header(no_jupytext_version_number):
    metadata = {"jupytext": {"mainlanguage": "python"}}
    nb = new_notebook(
        metadata=metadata,
        cells=[new_raw_cell(source="---\ntitle: Sample header\n---")])
    header, lines_to_next_cell = metadata_and_cell_to_header(
        nb, metadata, get_format_implementation(".md"), ".md")
    assert ("\n".join(header) == """---
title: Sample header
jupyter:
  jupytext:
    mainlanguage: python
---""")
    assert nb.cells == []
    assert lines_to_next_cell is None
Ejemplo n.º 5
0
def test_metadata_and_cell_to_header():
    metadata = {'jupytext': {'mainlanguage': 'python'}}
    nb = new_notebook(
        metadata=metadata,
        cells=[new_raw_cell(source="---\ntitle: Sample header\n---")])
    with mock.patch('jupytext.header.INSERT_AND_CHECK_VERSION_NUMBER', False):
        header, lines_to_next_cell = metadata_and_cell_to_header(nb, metadata, get_format_implementation('.md'), '.md')
    assert '\n'.join(header) == """---
title: Sample header
jupyter:
  jupytext:
    mainlanguage: python
---"""
    assert nb.cells == []
    assert lines_to_next_cell is None
Ejemplo n.º 6
0
def test_header_to_html_comment(no_jupytext_version_number):
    metadata = {
        "jupytext": {
            "mainlanguage": "python",
            "hide_notebook_metadata": True
        }
    }
    nb = new_notebook(metadata=metadata, cells=[])
    header, lines_to_next_cell = metadata_and_cell_to_header(
        nb, metadata, get_format_implementation(".md"), ".md")
    compare(
        "\n".join(header),
        """<!--

---
jupyter:
  jupytext:
    hide_notebook_metadata: true
    mainlanguage: python
---

-->""",
    )
Ejemplo n.º 7
0
def test_get_format_implementation():
    assert get_format_implementation('.py').format_name == 'light'
    assert get_format_implementation('.py', 'percent').format_name == 'percent'
    with pytest.raises(JupytextFormatError):
        get_format_implementation('.py', 'wrong_format')
Ejemplo n.º 8
0
def test_not_installed():
    with mock.patch("jupytext.formats.JUPYTEXT_FORMATS", return_value=[]):
        with pytest.raises(JupytextFormatError):
            get_format_implementation(".myst")
Ejemplo n.º 9
0
def test_get_format_implementation():
    assert get_format_implementation(".py").format_name == "light"
    assert get_format_implementation(".py", "percent").format_name == "percent"
    with pytest.raises(JupytextFormatError):
        get_format_implementation(".py", "wrong_format")