Exemplo n.º 1
0
 def testUseCLI(self):
     notebook_dir = path.join('tests', 'expected')
     for notebook_path in glob(path.join(notebook_dir, '*.ipynb')):
         notebook_file = path.basename(notebook_path)
         print(notebook_file)
         expected = ""
         with open(notebook_path) as notebook_file:
             expected = notebook_file.read()
         try:
             # IPython 3
             expected = reads(expected, 3)
         except (TypeError, NBFormatError):
             # IPython 2
             expected = reads(expected, 'json')
         exit_code = 1
         argv = sys.argv
         stdout = sys.stdout
         stderr = sys.stderr
         try:
             with open(devnull, "w") as devnull_filehandle:
                 sys.stdout = sys.stderr = devnull_filehandle
                 sys.argv = [
                     "runipy",
                     "-o", notebook_path,
                     "--html", notebook_path.replace(".ipynb", ".html")
                 ]
                 main()
         except SystemExit as e:
             exit_code = e.code
         finally:
             sys.argv = argv
             sys.stdout = stdout
             sys.stderr = stderr
         notebook = ""
         with open(notebook_path) as notebook_file:
             notebook = notebook_file.read()
         try:
             # IPython 3
             notebook = reads(notebook, 3)
         except (TypeError, NBFormatError):
             # IPython 2
             notebook = reads(notebook, 'json')
         self.assert_notebooks_equal(expected, notebook)
Exemplo n.º 2
0
 def testUseCLI(self):
     notebook_dir = path.join('tests', 'expected')
     for notebook_path in glob(path.join(notebook_dir, '*.ipynb')):
         notebook_file = path.basename(notebook_path)
         print(notebook_file)
         expected = ""
         with open(notebook_path) as notebook_file:
             expected = notebook_file.read()
         try:
             # IPython 3
             expected = reads(expected, 3)
         except (TypeError, NBFormatError):
             # IPython 2
             expected = reads(expected, 'json')
         exit_code = 1
         argv = sys.argv
         stdout = sys.stdout
         stderr = sys.stderr
         try:
             with open(devnull, "w") as devnull_filehandle:
                 sys.stdout = sys.stderr = devnull_filehandle
                 sys.argv = [
                     "runipy", "-o", notebook_path, "--html",
                     notebook_path.replace(".ipynb", ".html")
                 ]
                 main()
         except SystemExit as e:
             exit_code = e.code
         finally:
             sys.argv = argv
             sys.stdout = stdout
             sys.stderr = stderr
         notebook = ""
         with open(notebook_path) as notebook_file:
             notebook = notebook_file.read()
         try:
             # IPython 3
             notebook = reads(notebook, 3)
         except (TypeError, NBFormatError):
             # IPython 2
             notebook = reads(notebook, 'json')
         self.assert_notebooks_equal(expected, notebook)
if __name__ == '__main__':
    import sys
    from runipy.main import main

    sys.exit(main())