Exemplo n.º 1
0
 def test_admin_10(self):
     notebook = NotebookSageNB.find(DOT_SAGE, 'admin:10')
     self.assertEqual(notebook.unique_id, 'admin:10')
     self.assertEqual(notebook.name, 'Oxford Seminar (1,1)-Calabi Yau')
     cell = list(notebook.cells)
     self.assertEqual(len(cell), 37)
     # First cell
     self.assertIsInstance(cell[0], TextCell)
     self.assertEqual(cell[0].input,
                      '<h1 style="text-align: center;">The 24-Cell</h1>')
     # Second cell
     self.assertIsInstance(cell[1], ComputeCell)
     self.assertEqual(cell[1].index, 4)
     self.assertEqual(
         cell[1].input,
         'cell24 = polytopes.twenty_four_cell()\ncell24.f_vector()   # it is self-dual'
     )
     self.assertEqual(cell[1].input, cell[1].ipython_input())
     self.assertEqual(cell[1].output, '(1, 24, 96, 96, 24, 1)')
     self.assertEqual(cell[1].plain_text_output(), '(1, 24, 96, 96, 24, 1)')
     # Third cell (containing HTML)
     self.assertIsInstance(cell[2], ComputeCell)
     self.assertEqual(cell[2].index, 86)
     self.assertEqual(cell[2].input, 'cell24.f_vector?')
     self.assertEqual(cell[2].input, cell[2].ipython_input())
     self.assertIn('<html><!--notruncate-->\n\n<div class="docstring">',
                   cell[2].output)
     self.assertEqual(cell[2].plain_text_output(), '')
Exemplo n.º 2
0
 def notebook(self):
     try:
         nb = self._notebook
     except AttributeError:
         nb = self._notebook = NotebookSageNB.find(self.dot_sage,
                                                   self.unique_id)
     return nb
Exemplo n.º 3
0
 def test_aleksandra_slapik_44(self):
     notebook = NotebookSageNB.find(DOT_SAGE, 'aleksandra.slapik:44')
     ipynb = IpynbWriter(notebook)
     ipynb.write(self.tmp_filename('aleksandra_slapik_44.ipynb'))
     ipynb.write(
         self.tmp_filename(
             u'WDI projekt - R\xf3\u017cankowski, Kie\u0142pi\u0144ski, Kozok.ipynb'
         ))
Exemplo n.º 4
0
 def notebook_iter(self):
     dot_sage = os.path.expanduser(DOT_SAGE)
     notebooks = dict((notebook.sort_key, notebook)
                      for notebook in NotebookSageNB.all_iter(dot_sage))
     for key in sorted(notebooks.keys()):
         # Skip notebooks with owner _sage_ which come from live
         # documentation and are not real notebooks
         if key[0] == "_sage_":
             continue
         yield notebooks[key]
Exemplo n.º 5
0
def action_list(dot_sage):
    def tr(unique_id, name):
        print('{0:<15} | {1}'.format(unique_id, name))

    tr('Unique ID', 'Notebook Name')
    print('-' * 79)
    notebooks = dict((notebook.sort_key, notebook)
                     for notebook in NotebookSageNB.all_iter(dot_sage))
    for key in sorted(notebooks.keys()):
        notebook = notebooks[key]
        tr(notebook.unique_id, notebook.name)
Exemplo n.º 6
0
 def test_sage_4(self):
     notebook = NotebookSageNB.find(DOT_SAGE, '_sage_:4')
     self.assertEqual(notebook.unique_id, '_sage_:4')
     self.assertEqual(
         notebook.name,
         'Welcome to the Sage Tutorial! -- Sage Tutorial v6.4.rc1')
     cell = list(notebook.cells)
     self.assertEqual(len(cell), 2)
     self.assertEqual(type(cell[0].input), string_type)
     self.assertEqual(type(cell[1].input), string_type)
     self.assertEqual(type(cell[1].output), string_type)
Exemplo n.º 7
0
 def test_sage_4(self):
     notebook = NotebookSageNB.find(DOT_SAGE, '_sage_:4')
     self.assertEqual(notebook.unique_id, '_sage_:4')
     self.assertEqual(notebook.name, 'Welcome to the Sage Tutorial! -- Sage Tutorial v6.4.rc1')
     cell = list(notebook.cells)
     self.assertEqual(len(cell), 2)
     self.assertEqual(type(cell[0].input), unicode)
     self.assertEqual(type(cell[1].input), unicode)
     self.assertEqual(type(cell[1].output), unicode)
     ipynb = IpynbWriter(notebook)
     ipynb.write('/dev/null')
Exemplo n.º 8
0
def action_list(dot_sage):
    def tr(unique_id, name):
        print(u'{0:<15} | {1}'.format(unique_id, name))
    tr('Unique ID', 'Notebook Name')
    print('-' * 79)
    notebooks = dict(
        (notebook.sort_key, notebook)
        for notebook in NotebookSageNB.all_iter(dot_sage)
    )
    for key in sorted(notebooks.keys()):
        notebook = notebooks[key]
        tr(notebook.unique_id, notebook.name)
Exemplo n.º 9
0
 def test_sage_4(self):
     notebook = NotebookSageNB.find(DOT_SAGE, '_sage_:4')
     self.assertEqual(notebook.unique_id, '_sage_:4')
     self.assertEqual(
         notebook.name,
         'Welcome to the Sage Tutorial! -- Sage Tutorial v6.4.rc1')
     cell = list(notebook.cells)
     self.assertEqual(len(cell), 2)
     self.assertEqual(type(cell[0].input), unicode)
     self.assertEqual(type(cell[1].input), unicode)
     self.assertEqual(type(cell[1].output), unicode)
     ipynb = IpynbWriter(notebook)
     ipynb.write('/dev/null')
Exemplo n.º 10
0
 def test_admin_6(self):
     notebook = NotebookSageNB.find(DOT_SAGE, 'admin:6')
     self.assertEqual(notebook.unique_id, 'admin:6')
     self.assertEqual(notebook.name, 'Test %cython')
     cell_list = list(notebook.cells)
     self.assertEqual(len(cell_list), 2)
     # First cell
     cell0 = cell_list[0]
     self.assertIsInstance(cell0, ComputeCell)
     self.assertEqual(
         cell0.input,
         '%hide\n%cython\ncdef str x = "Hello World"\nprint(x)')
     self.assertEqual(cell0.ipython_input(),
                      '%%cython\ncdef str x = "Hello World"\nprint(x)')
Exemplo n.º 11
0
 def test_list(self):
     nbks = list(NotebookSageNB.all_iter(DOT_SAGE))
     self.assertEqual(len(nbks), 5)
     sage_4, admin_4, admin_6, admin_10, aleks = sorted(nbks)
     self.assertEqual(sage_4.unique_id, '_sage_:4')
     self.assertEqual(
         sage_4.name,
         u'Welcome to the Sage Tutorial! -- Sage Tutorial v6.4.rc1')
     self.assertEqual(admin_4.unique_id, 'admin:4')
     self.assertEqual(admin_4.name, u'MathJax_problem1')
     self.assertEqual(admin_10.unique_id, 'admin:10')
     self.assertEqual(admin_10.name, u'Oxford Seminar (1,1)-Calabi Yau')
     self.assertEqual(aleks.unique_id, 'aleksandra.slapik:44')
     self.assertEqual(
         aleks.name,
         u'WDI projekt - R\xf3\u017cankowski, Kie\u0142pi\u0144ski, Kozok')
Exemplo n.º 12
0
 def test_admin_10(self):
     notebook = NotebookSageNB.find(DOT_SAGE, 'admin:10')
     self.assertEqual(notebook.unique_id, 'admin:10')
     self.assertEqual(notebook.name, 'Oxford Seminar (1,1)-Calabi Yau')
     cell = list(notebook.cells)
     self.assertEqual(len(cell), 37)
     # First cell
     self.assertIsInstance(cell[0], TextCell)
     self.assertEqual(cell[0].input, '<h1 style="text-align: center;">The 24-Cell</h1>')
     # Second cell
     self.assertIsInstance(cell[1], ComputeCell)
     self.assertEqual(cell[1].index, 4)
     self.assertEqual(
         cell[1].input,
         'cell24 = polytopes.twenty_four_cell()\ncell24.f_vector()   # it is self-dual')
     self.assertEqual(cell[1].output, '(1, 24, 96, 96, 24, 1)')
Exemplo n.º 13
0
 def test_admin_10(self):
     notebook = NotebookSageNB.find(DOT_SAGE, 'admin:10')
     self.assertEqual(notebook.unique_id, 'admin:10')
     self.assertEqual(notebook.name, 'Oxford Seminar (1,1)-Calabi Yau')
     cell = list(notebook.cells)
     self.assertEqual(len(cell), 37)
     # First cell
     self.assertIsInstance(cell[0], TextCell)
     self.assertEqual(cell[0].input,
                      '<h1 style="text-align: center;">The 24-Cell</h1>')
     # Second cell
     self.assertIsInstance(cell[1], ComputeCell)
     self.assertEqual(cell[1].index, 4)
     self.assertEqual(
         cell[1].input,
         'cell24 = polytopes.twenty_four_cell()\ncell24.f_vector()   # it is self-dual'
     )
     self.assertEqual(cell[1].output, '(1, 24, 96, 96, 24, 1)')
Exemplo n.º 14
0
 def test_admin_4(self):
     notebook = NotebookSageNB.find(DOT_SAGE, 'admin:4')
     self.assertEqual(notebook.unique_id, 'admin:4')
     self.assertEqual(notebook.name, u'MathJax_problem1')
     cell_list = list(notebook.cells)
     self.assertEqual(len(cell_list), 2)
     # First cell
     cell0 = cell_list[0]
     self.assertIsInstance(cell0, TextCell)
     self.assertEqual(
         cell0.input,
         u'<h2>R\xf3wnanie Newtona</h2>\n<h2>$$\\vec F= m\\vec a$$\xa0</h2>\n<p>Rzut pionowy</p>\n<p>$$F= m a$$\xa0</p>\n<p>\xa0</p>\n<h2>\xa0Krok czasowy: $\\Delta t$.</h2>\n<p>\xa0</p>\n<ul>\n<li>$ \xa0v\xa0=\xa0\\displaystyle\\frac{ \\Delta \xa0y}{\\Delta t}$</li>\n</ul>\n<ul>\n<li>$ \xa0a\xa0=\xa0 \\displaystyle \\frac{\\Delta \xa0v}{\\Delta t}$</li>\n</ul>\n<div>\xa0</div>\n<p>$$\\begin{cases} \\quad \\displaystyle \\frac{\\Delta y}{\\Delta t} &=& v \\\\ \\quad \\displaystyle \\frac{\\Delta v}{\\Delta t} &=& \\displaystyle \\frac { F}{m} \\end{cases} $$</p>\n<p>\xa0</p>\n<p>\xa0</p>\n<div>\xa0$\\:y_0\\:$ \xa0i $\\:v_{0}\\:$</div>\n<p>$$\\begin{cases}<br />\\quad y &=&y_0\\ +\\ v_{0}\\:\\Delta t\\\\\xa0<br /><br />\\quad v &=&v_{0}\\ +\\ \xa0\\frac{F}{m}\\:\\Delta t \\end{cases}$$</p>'
     )
     # Second cell
     cell1 = cell_list[1]
     self.assertIsInstance(cell1, ComputeCell)
     self.assertEqual(cell1.index, 1)
     self.assertEqual(cell1.input, '')
     self.assertEqual(cell1.output, '')
     self.assertEqual(cell1.plain_text_output(), '')
Exemplo n.º 15
0
def main():
    parser = make_parser()
    args = parser.parse_args()
    if args.log is not None:
        import logging
        level = getattr(logging, args.log)
        log.setLevel(level=level)
    dot_sage = os.path.expanduser(args.dot_sage)
    if args.list:
        action_list(dot_sage)

    if not args.sagenb:
        sys.exit(0)
    sagenb = NotebookSageNB.find(dot_sage, args.sagenb)

    if args.print_text:
        action_print(sagenb)

    if args.ipynb:
        ipynb_name = args.ipynb.format(nb=sagenb)
        if os.path.exists(ipynb_name):
            raise RuntimeError('file exists: {0}'.format(ipynb_name))
        action_convert_ipynb(sagenb, ipynb_name)
Exemplo n.º 16
0
def main():
    parser = make_parser()
    args = parser.parse_args()
    if args.log is not None:
        import logging
        level = getattr(logging, args.log)
        log.setLevel(level=level)
    dot_sage = os.path.expanduser(args.dot_sage)
    if args.list:
        action_list(dot_sage)

    if not args.sagenb:
        sys.exit(0)
    sagenb = NotebookSageNB.find(dot_sage, args.sagenb)

    if args.print_text:
        action_print(sagenb)

    if args.ipynb:
        ipynb_name = args.ipynb.format(nb=sagenb)
        if os.path.exists(ipynb_name):
            raise RuntimeError('file exists: {0}'.format(ipynb_name))
        action_convert_ipynb(sagenb, ipynb_name)
Exemplo n.º 17
0
 def notebook(self):
     try:
         nb = self._notebook
     except AttributeError:
         nb = self._notebook = NotebookSageNB.find(self.dot_sage, self.unique_id)
     return nb
Exemplo n.º 18
0
 def test_list(self):
     nbks = list(NotebookSageNB.all_iter(DOT_SAGE))
     self.assertTrue(len(nbks), 1)
Exemplo n.º 19
0
 def test_sage_4(self):
     notebook = NotebookSageNB.find(DOT_SAGE, '_sage_:4')
     ipynb = IpynbWriter(notebook)
     ipynb.write(self.tmp_filename('sage:4.ipynb'))
Exemplo n.º 20
0
 def test_list(self):
     nbks = list(NotebookSageNB.all_iter(DOT_SAGE))
     self.assertTrue(len(nbks), 1)
Exemplo n.º 21
0
 def notebook_iter(self):
     dot_sage = os.path.expanduser(DOT_SAGE)
     notebooks = dict((notebook.sort_key, notebook)
                      for notebook in NotebookSageNB.all_iter(dot_sage))
     for key in sorted(notebooks.keys()):
         yield notebooks[key]