How to use the jupytext.compare.compare 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_read_simple_markdown.py View on Github external
def test_raw_cell_with_metadata(markdown="""
raw content

"""):
    nb = jupytext.reads(markdown, 'md')
    compare(nb.cells[0], new_raw_cell(source='raw content', metadata={'key': 'value'}))
    markdown2 = jupytext.writes(nb, 'md')
    compare(markdown2, markdown)
github mwouts / jupytext / tests / test_cell_metadata.py View on Github external
def test_title_no_metadata(text='title', value=('title', {})):
    compare(text_to_metadata(text, allow_title=True), value)
    assert metadata_to_text(*value) == text.strip()
github mwouts / jupytext / tests / test_read_simple_python.py View on Github external
pynb="""def test_read_cell_explicit_start_end(pynb='''
import pandas as pd
# +
def data():
    return pd.DataFrame({'A': [0, 1]})


data()
'''):
    nb = jupytext.reads(pynb, 'py')
    pynb2 = jupytext.writes(nb, 'py')
    compare(pynb2, pynb)
"""):
    nb = jupytext.reads(pynb, 'py')
    pynb2 = jupytext.writes(nb, 'py')
    compare(pynb2, pynb)
github mwouts / jupytext / tests / test_cell_metadata.py View on Github external
def test_parse_rmd_options(options, language_and_metadata):
    compare(rmd_options_to_metadata(options), language_and_metadata)
github mwouts / jupytext / tests / test_active_cells.py View on Github external
def test_active_ipynb_rmd_using_tags(ext, no_jupytext_version_number):
    nb = jupytext.reads(HEADER[ext] + ACTIVE_IPYNB_RMD_USING_TAG[ext], ext)
    assert len(nb.cells) == 1
    compare(jupytext.writes(nb, ext), ACTIVE_IPYNB_RMD_USING_TAG[ext])
    compare(nb.cells[0], ACTIVE_IPYNB_RMD_USING_TAG['.ipynb'])
github mwouts / jupytext / tests / test_read_simple_python.py View on Github external
def test_read_markdown_cell_with_triple_quote_307(
        script="""# This script test that commented triple quotes '''
# do not impede the correct identification of Markdown cells

# Here is Markdown cell number 2 '''
"""):
    notebook = jupytext.reads(script, 'py')
    assert len(notebook.cells) == 2
    assert notebook.cells[0].cell_type == 'markdown'
    assert notebook.cells[0].source == """This script test that commented triple quotes '''
do not impede the correct identification of Markdown cells"""
    assert notebook.cells[1].cell_type == 'markdown'
    assert notebook.cells[1].source == "Here is Markdown cell number 2 '''"

    script2 = jupytext.writes(notebook, 'py')
    compare(script2, script)
github mwouts / jupytext / tests / test_read_simple_python.py View on Github external
# +
# Final cell

1 + 1
"""):
    notebook = jupytext.reads(script, 'py')
    assert len(notebook.cells) == 3
    for cell in notebook.cells:
        lines = cell.source.splitlines()
        if len(lines) != 1:
            assert lines[0]
            assert lines[-1]

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

    compare(script2, script)
github mwouts / jupytext / tests / test_read_simple_markdown.py View on Github external
def test_markdown_cell_with_metadata(markdown="""
A long


markdown cell

"""):
    nb = jupytext.reads(markdown, 'md')
    compare(nb.cells[0], new_markdown_cell(source='A long\n\n\nmarkdown cell',
                                           metadata={'key': 'value'}))
    markdown2 = jupytext.writes(nb, 'md')
    compare(markdown2, markdown)
github mwouts / jupytext / tests / test_read_simple_markdown.py View on Github external
def test_code_cell_with_metadata(markdown="""```python tags=["parameters"]
a = 1
b = 2

"""): nb = jupytext.reads(markdown, 'md') compare(nb.cells[0], new_code_cell(source='a = 1\nb = 2', metadata={'tags': ['parameters']})) markdown2 = jupytext.writes(nb, 'md') compare(markdown2, markdown)

github mwouts / jupytext / jupytext / cli.py View on Github external
update=args.update,
                                           allow_expected_differences=not args.test_strict,
                                           stop_on_first_error=args.stop_on_first_error)

            # Round trip from a text file
            else:
                with open(nb_file) as fp:
                    org_text = fp.read()

                # If the destination is not ipynb, we convert to/back that format
                if dest_fmt['extension'] != '.ipynb':
                    dest_text = writes(notebook, fmt=dest_fmt)
                    notebook = reads(dest_text, fmt=dest_fmt)

                text = writes(notebook, fmt=fmt)
                compare(text, org_text)

        except (NotebookDifference, AssertionError) as err:
            sys.stdout.write('{}: {}'.format(nb_file, str(err)))
            return 1
        return 0

    # b. Output to the desired file or format
    if nb_dest:
        if nb_dest == nb_file and not dest_fmt:
            dest_fmt = fmt

        # Test consistency between dest name and output format
        if dest_fmt and nb_dest != '-':
            base_path(nb_dest, dest_fmt)

        # Describe what jupytext is doing