示例#1
0
def test_regression():
    # Test documentation worked example
    input_nb_fname = pjoin(DATA, 'example_notebook.ipynb')
    output_rst_fname = pjoin(DATA, 'converted_example.rst')
    # Convert to ReST, add trailing CR from output script
    rst = convert_nb_fname(input_nb_fname) + '\n'
    assert rst.encode('utf8') == fcontents(output_rst_fname)
    # Convert ReST to output formats
    py_file = to_py.from_rst(rst)
    assert (py_file.encode('utf8') == fcontents(
        pjoin(DATA, 'converted_plus_notebooks.py')))
    ipy_file = to_notebook.from_rst(rst)
    assert_nb_equiv(
        ipy_file,
        fcontents(pjoin(DATA,
                        'converted_plus_notebooks.ipynb')).decode('utf8'))
示例#2
0
def test_default_mathdollar():
    # Test mathdollar extension present by default.
    ipynb = to_notebook.from_rst(r'Some text with $a = 1$ math.')
    expected = r"""{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Some text with $a = 1$ math."
   ]
  }
 ],
 "metadata": {},
 "nbformat": 4,
 "nbformat_minor": 1
}"""
    assert_nb_equiv(ipynb, expected)
示例#3
0
def assert_rst_cells_equal(rst_text, cells):
    actual = to_notebook.from_rst(rst_text)
    expected = cells2json(cells)
    assert actual == expected
示例#4
0
def to_nb_safe(rst_str):
    out = to_notebook.from_rst(rst_str)
    return unsmart_nb(out)
示例#5
0
def test_notebook_basic():
    # Test conversion of basic ReST to ipynb JSON
    ipynb = to_notebook.from_rst(r"""
Title
=====

Some text with :math:`a = 1` math.

.. math::

    \textrm{math block}

.. nbplot::

    >>> c = 1
    >>> c
    1

More text.

.. nbplot::

    >>> d = 2
    >>> d
    2""")
    expected = r"""{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Title\n",
    "\n",
    "Some text with $a = 1$ math.\n",
    "\n",
    "$$\n",
    "\\textrm{math block}\n",
    "$$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "c = 1\n",
    "c"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "More text."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "d = 2\n",
    "d"
   ]
  }
 ],
 "metadata": {},
 "nbformat": 4,
 "nbformat_minor": 1
}"""
    assert_nb_equiv(ipynb, expected)
示例#6
0
def assert_rst_cells_equal(rst_text, cells):
    actual = to_notebook.from_rst(rst_text)
    expected = cells2json(cells)
    assert rm_json_id(actual) == rm_json_id(expected)
示例#7
0
def assert_conv_equal(rst_str, expected):
    assert_nb_equiv(to_notebook.from_rst(rst_str), expected)