def test_apply_black_on_python_notebooks(nb_file, tmpdir): tmp_ipynb = str(tmpdir.join('notebook.ipynb')) tmp_py = str(tmpdir.join('notebook.py')) copyfile(nb_file, tmp_ipynb) jupytext(args=[tmp_ipynb, '--to', 'py:percent']) system('black', tmp_py) jupytext(args=[tmp_py, '--to', 'ipynb', '--update']) nb1 = readf(nb_file) nb2 = readf(tmp_ipynb) nb3 = readf(tmp_py) assert len(nb1.cells) == len(nb2.cells) assert len(nb1.cells) == len(nb3.cells) for c1, c2 in zip(nb1.cells, nb2.cells): # same content (almost) assert black_invariant(c1.source) == black_invariant(c2.source) # python representation is pep8 assert 'lines_to_next_cell' not in c2.metadata # outputs are preserved assert c1.cell_type == c2.cell_type if c1.cell_type == 'code': compare(c1.outputs, c2.outputs) compare(nb1.metadata, nb2.metadata)
def test_apply_black_on_python_notebooks(nb_file, tmpdir): tmp_ipynb = str(tmpdir.join("notebook.ipynb")) tmp_py = str(tmpdir.join("notebook.py")) copyfile(nb_file, tmp_ipynb) jupytext(args=[tmp_ipynb, "--to", "py:percent"]) system("black", tmp_py) jupytext(args=[tmp_py, "--to", "ipynb", "--update"]) nb1 = read(nb_file) nb2 = read(tmp_ipynb) nb3 = read(tmp_py) assert len(nb1.cells) == len(nb2.cells) assert len(nb1.cells) == len(nb3.cells) for c1, c2 in zip(nb1.cells, nb2.cells): # same content (almost) assert black_invariant(c1.source) == black_invariant(c2.source) # python representation is pep8 assert "lines_to_next_cell" not in c2.metadata # outputs are preserved assert c1.cell_type == c2.cell_type if c1.cell_type == "code": compare(c1.outputs, c2.outputs) compare(nb1.metadata, nb2.metadata)
def test_black_invariant(): text_org = """long_string = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" \\ "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb" """ text_black = """long_string = ( "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb" ) """ assert black_invariant(text_org) == black_invariant(text_black)