Skip to content

Commit

Permalink
Test preferred_jupytext_formats_read auto:percent #93
Browse files Browse the repository at this point in the history
  • Loading branch information
mwouts committed Oct 10, 2018
1 parent b58964f commit 8905701
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions tests/test_contentsmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -382,15 +382,38 @@ def test_preferred_format_allows_to_read_implicit_light_format(nb_file, tmpdir):

# create contents manager with default load format as percent
cm = jupytext.TextFileContentsManager()
cm.preferred_jupytext_formats_load = 'py:percent'
cm.preferred_jupytext_formats_read = 'py:percent'
cm.root_dir = str(tmpdir)

# load notebook
with mock.patch('jupytext.header.INSERT_AND_CHECK_VERSION_NUMBER', True):
model = cm.get(tmp_nbpy)

# check that format (missing) is recognized as light
assert 'py:light' in model['content']['metadata']['jupytext']['formats']
if 'light' in nb_file:
assert 'py:light' in model['content']['metadata']['jupytext']['formats']
else:
assert 'py:percent' in model['content']['metadata']['jupytext']['formats']


def test_preferred_formats_read_auto(tmpdir):
tmp_py = u'notebook.py'
with open(str(tmpdir.join(tmp_py)), 'w') as script:
script.write("""# cell one
1 + 1
""")

# create contents manager with default load format as percent
cm = jupytext.TextFileContentsManager()
cm.preferred_jupytext_formats_read = 'auto:percent'
cm.root_dir = str(tmpdir)

# load notebook
with mock.patch('jupytext.header.INSERT_AND_CHECK_VERSION_NUMBER', True):
model = cm.get(tmp_py)

# check that script is open as percent
assert 'py:percent' in model['content']['metadata']['jupytext']['formats']


@pytest.mark.parametrize('nb_file', list_notebooks('ipynb'))
Expand Down

0 comments on commit 8905701

Please sign in to comment.