How to use the jupytext.reads function in jupytext

To help you get started, we’ve selected a few jupytext examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mwouts / jupytext / tests / test_preserve_empty_cells.py View on Github external
def test_file_with_blank_lines(blank_lines):
    py_script = """# Markdown cell{0}
# Another one{0}
""".format('\n'.join([''] * blank_lines))

    notebook = jupytext.reads(py_script, 'py')
    py_script2 = jupytext.writes(notebook, 'py')
    compare(py_script2, py_script)
github mwouts / jupytext / tests / test_active_cells.py View on Github external
def test_active_not_include_rmd(ext, no_jupytext_version_number):
    nb = jupytext.reads(ACTIVE_NOT_INCLUDE_RMD[ext], ext)
    assert len(nb.cells) == 1
    compare(jupytext.writes(nb, ext), ACTIVE_NOT_INCLUDE_RMD[ext])
    compare(nb.cells[0], ACTIVE_NOT_INCLUDE_RMD['.ipynb'])
github mwouts / jupytext / tests / test_read_simple_python.py View on Github external
def test_notebook_with_magic_and_bash_cells(script="""# This is a test for issue #181

# %load_ext line_profiler

# !head -4 data/president_heights.csv
"""):
    notebook = jupytext.reads(script, 'py')
    for cell in notebook.cells:
        lines = cell.source.splitlines()
        assert lines[0]
        assert lines[-1]
        assert not cell.metadata, cell.source

    script2 = jupytext.writes(notebook, 'py')

    compare(script2, script)
github mwouts / jupytext / tests / test_read_simple_rmd.py View on Github external
def test_markdown_cell_with_code_works(nb=new_notebook(cells=[
    new_markdown_cell("""```python
1 + 1
```""")])):
    text = jupytext.writes(nb, 'Rmd')
    nb2 = jupytext.reads(text, 'Rmd')
    compare_notebooks(nb2, nb)
github mwouts / jupytext / tests / test_read_simple_markdown.py View on Github external
language: python
    name: python3
  extra:
    key: value
---
""", target="""---
jupyter:
  jupytext:
    notebook_metadata_filter: -extra
  kernelspec:
    display_name: Python 3
    language: python
    name: python3
---
"""):
    nb = jupytext.reads(org, 'md')
    text = jupytext.writes(nb, 'md')
    compare(text, target)
github mwouts / jupytext / tests / test_read_simple_R.py View on Github external
#' Here we have some text
#' And below we have some R code

# This is a comment about function f
f <- function(x) {

    return(x+1)}


# And a comment on h
h <- function(y) {
    return(y-1)
}
"""):
    nb = jupytext.reads(rnb, ext)

    assert len(nb.cells) == 4
    assert nb.cells[0].cell_type == 'raw'
    assert nb.cells[0].source == '---\ntitle: Less simple file\n---'
    assert nb.cells[1].cell_type == 'markdown'
    assert nb.cells[1].source == 'Here we have some text\n' \
                                 'And below we have some R code'
    assert nb.cells[2].cell_type == 'code'
    compare(nb.cells[2].source,
            """# This is a comment about function f
f <- function(x) {

    return(x+1)}""")
    assert nb.cells[3].cell_type == 'code'
    compare(nb.cells[3].source,
            '''# And a comment on h
github mwouts / jupytext / tests / test_read_simple_markdown.py View on Github external
def test_read_markdown_IDL(no_jupytext_version_number, text='''---
jupyter:
  kernelspec:
    display_name: IDL [conda env:gdl] *
    language: IDL
    name: conda-env-gdl-idl
---

# A sample IDL Markdown notebook

```IDL
a = 1

'''): nb = jupytext.reads(text, 'md') assert len(nb.cells) == 2 assert nb.cells[1].cell_type == 'code' assert nb.cells[1].source == 'a = 1'

text2 = jupytext.writes(nb, 'md')
compare(text2, text.replace('```IDL', '```idl'))
github mwouts / jupytext / tests / test_read_simple_python.py View on Github external
def test_round_trip_markdown_cell_with_magic():
    notebook = new_notebook(cells=[new_markdown_cell('IPython has magic commands like\n%quickref')],
                            metadata={'jupytext': {'main_language': 'python'}})
    text = jupytext.writes(notebook, 'py')
    notebook2 = jupytext.reads(text, 'py')
    compare_notebooks(notebook2, notebook)
github mwouts / jupytext / tests / test_read_incomplete_rmd.py View on Github external
title: Unterminated header

```{python}
1+3

some text

1+4
1+5
"""):
    nb = jupytext.reads(rmd, 'Rmd')
    assert len(nb.cells) == 5
    assert nb.cells[0].cell_type == 'markdown'
    assert nb.cells[0].source == '---\ntitle: Unterminated header'
    assert nb.cells[1].cell_type == 'code'
    assert nb.cells[1].source == '1+3'
    assert nb.cells[2].cell_type == 'markdown'
    assert nb.cells[2].source == 'some text'
    assert nb.cells[3].cell_type == 'code'
    assert nb.cells[3].source == '%%R\n1+4'
    assert nb.cells[4].cell_type == 'code'
    assert nb.cells[4].metadata == {'name': 'not_terminated'}
    assert nb.cells[4].source == '1+5'
github mwouts / jupytext / tests / test_read_simple_python.py View on Github external
# title: Less simple file
# ---

# Here we have some text
# And below we have some python code

# This is a comment about function f
def f(x):
    return x+1


# And a comment on h
def h(y):
    return y-1
"""):
    nb = jupytext.reads(pynb, 'py')

    assert len(nb.cells) == 4
    assert nb.cells[0].cell_type == 'raw'
    assert nb.cells[0].source == '---\ntitle: Less simple file\n---'
    assert nb.cells[1].cell_type == 'markdown'
    assert nb.cells[1].source == 'Here we have some text\n' \
                                 'And below we have some python code'
    assert nb.cells[2].cell_type == 'code'
    compare(nb.cells[2].source,
            '# This is a comment about function f\n'
            'def f(x):\n'
            '    return x+1')
    assert nb.cells[3].cell_type == 'code'
    compare(nb.cells[3].source,
            '''# And a comment on h\ndef h(y):\n    return y-1''')