def test_convert_single_file(nb_file, capsys): nb1 = readf(nb_file) pynb = writes(nb1, ext='.py') convert_notebook_files([nb_file], ext='.py', output='-') out, err = capsys.readouterr() assert err == '' compare(out, pynb)
def test_convert_single_file_in_place(nb_file, tmpdir): nb_org = str(tmpdir.join(os.path.basename(nb_file))) base, ext = os.path.splitext(nb_org) nb_other = base + '.py' copyfile(nb_file, nb_org) convert_notebook_files([nb_org], ext='.py') nb1 = readf(nb_org) nb2 = readf(nb_other) compare_notebooks(nb1, nb2)
def test_convert_multiple_file(nb_files, tmpdir): nb_orgs = [] nb_others = [] for nb_file in nb_files: nb_org = str(tmpdir.join(os.path.basename(nb_file))) base, ext = os.path.splitext(nb_org) nb_other = base + '.py' copyfile(nb_file, nb_org) nb_orgs.append(nb_org) nb_others.append(nb_other) convert_notebook_files(nb_orgs, ext='.py') for nb_org, nb_other in zip(nb_orgs, nb_others): nb1 = readf(nb_org) nb2 = readf(nb_other) compare_notebooks(nb1, nb2)
def test_error_not_same_ext(nb_file=list_notebooks()[0]): with pytest.raises(TypeError): convert_notebook_files([nb_file], ext='.py', output='not.ext')
def test_error_not_notebook_ext_dest1(nb_file=list_notebooks()[0]): with pytest.raises(TypeError): convert_notebook_files([nb_file], ext='.ext')
def test_error_not_notebook_ext_input(nb_file='notebook.ext'): with pytest.raises(TypeError): convert_notebook_files([nb_file], ext='.py')
def test_error_multiple_input(nb_files=list_notebooks()): with pytest.raises(ValueError): convert_notebook_files(nb_files, ext='.py', output='notebook.py')
def test_error_multiple_input(nb_files=list_all_notebooks('.ipynb')): with pytest.raises(ValueError): convert_notebook_files(nb_files, 'notebook.py')
def test_error_not_notebook_ext_dest(nb_file=list_all_notebooks('.ipynb')[0]): with pytest.raises(TypeError): convert_notebook_files([nb_file], '.ext')