def test_build_with_fixes_links(tmp_project): project = tmp_project (project / "doc").mkdir() (project / "doc" / "conf.py").write_text(CONF_CONTENT) (project / "examples" / "index.ipynb").write_text(EXAMPLE_0_CONTENT) generate_rst("test_project", project_root=str(project)) build('html', str(project / "builtdocs"), project_root=str(project), examples_assets='') assert (project / "doc" / "1_First_Notebook.ipynb").is_file() assert (project / "builtdocs" / "First_Notebook.html").is_file() html = (project / "builtdocs" / "First_Notebook.html").read_text() assert '<a href="Zeroth_Notebook.html">right number</a>' in html assert '<a href="Zeroth_Notebook.html">wrong number</a>' in html assert '<a href="Zeroth_Notebook.html">no number</a>' in html
def test_generate_rst_with_no_nblink_set_defaults_to_bottom(tmp_project): expected = ['******************', 'Example Notebook 1', '******************', '', '.. notebook:: test_project ../examples/Example_Notebook_1.ipynb', ' :offset: 0', '', '', '-------', '', '`Right click to download this notebook from GitHub. <https://raw.githubusercontent.com/pyviz/nbsite/master/examples/Example_Notebook_1.ipynb>`_'] project = tmp_project generate_rst("test_project", project_root=str(project), host='GitHub', org='pyviz', repo='nbsite', branch='master') rstpath = (project / "doc" / "Example_Notebook_1.rst") assert rstpath.is_file() with open(rstpath, 'r') as f: contents = f.read().splitlines() assert contents[5:] == expected
def test_build_with_nblink_at_top_succeeds(tmp_project_with_docs_skeleton): project = tmp_project_with_docs_skeleton generate_rst("test_project", project_root=str(project), nblink='top', host='GitHub', org='pyviz', repo='nbsite', branch='master') rstpath = (project / "doc" / "First_Notebook.rst") assert rstpath.is_file() build('html', str(project / "builtdocs"), project_root=str(project), examples_assets='') assert (project / "builtdocs" / "First_Notebook.html").is_file() html = (project / "builtdocs" / "First_Notebook.html").read_text() assert 'This is another temporary notebook that gets created for tests' in html, \ "The notebook did not get build to html properly - look for sphinx warnings and errors"
def test_generate_rst_with_nblink_as_none(tmp_project): expected = [ '**************', 'First Notebook', '**************', '', '.. notebook:: test_project ../examples/1_First_Notebook.ipynb', ' :offset: 0' ] project = tmp_project generate_rst("test_project", project_root=str(project), nblink='none', host='GitHub', org='pyviz', repo='nbsite', branch='master') rstpath = (project / "doc" / "First_Notebook.rst") assert rstpath.is_file() with open(rstpath, 'r') as f: contents = f.read().splitlines() assert contents[5:] == expected
def test_generate_rst_with_skip_one_notebook(tmp_project): project = tmp_project generate_rst("test_project", project_root=str(project), skip='.*0_.*') assert not (project / "doc" / "Zeroth_Notebook.rst").is_file() assert (project / "doc" / "First_Notebook.rst").is_file()
def test_generate_rst_with_skip_glob_matching_both_notebooks_undercase(tmp_project): project = tmp_project generate_rst("test_project", project_root=str(project), skip='.*example.*') assert not (project / "doc" / "Example_Notebook_0.rst").is_file() assert not (project / "doc" / "Example_Notebook_1.rst").is_file()
def test_generate_rst_with_skip_list_of_notebooks(tmp_project): project = tmp_project generate_rst("test_project", project_root=str(project), skip='.*Notebook_0.*, .*Notebook_1.*') assert not (project / "doc" / "Example_Notebook_0.rst").is_file() assert not (project / "doc" / "Example_Notebook_1.rst").is_file()
def test_generate_rst(tmp_project): project = tmp_project generate_rst("test_project", project_root=str(project)) assert (project / "doc" / "Example_Notebook_0.rst").is_file() assert (project / "doc" / "Example_Notebook_1.rst").is_file()
#!/usr/bin/env python import sys import os from nbsite.cmd import generate_rst # if only someone had made a way to handle parameters org = sys.argv[1] project = sys.argv[2] examples_path = os.path.abspath(sys.argv[3]) doc_path = os.path.abspath(sys.argv[4]) offset = 0 overwrite = bool(1) if len(sys.argv) > 5: offset = int(sys.argv[5]) if len(sys.argv) > 6: overwrite = int(sys.argv[6]) generate_rst(project, examples=examples_path, doc=doc_path, org=org, repo=project, offset=offset, overwrite=bool(overwrite))