def test_run_and_save(self): src_file = os.path.join(TEST_DIR, 'sample_notebook.ipynb') dst_file = os.path.join(TEST_DIR, 'sample_notebook_executed.ipynb') n_errors = run_and_save(src_file, dst_file) self.assertEqual(n_errors, 0) with open(dst_file) as f: contents = f.read() # This is a cheap way to make sure the output is correct. # It is dependent on sample_notebook.ipynb. self.assertIn('-0.022165', contents) # Mean of X self.assertIn('The median is 0.000692', contents) # Median of X os.remove(dst_file)
#!python import argparse import batch_notebook if __name__ == "__main__": desc = "Run IPython notebook scripts in batch mode." parser = argparse.ArgumentParser(description=desc) parser.add_argument("src", help="source notebook path") parser.add_argument("dst", help="destination notebook path") parser.add_argument("--timeout", "-T", help="max execution time in seconds per cell", type=int) parser.add_argument("--verbose", "-V", action="store_true", help="print status messages as processing proceeds") args = parser.parse_args() kwargs = {} if args.timeout: kwargs["timeout"] = args.timeout if args.verbose: kwargs["verbose"] = args.verbose batch_notebook.run_and_save(args.src, args.dst, **kwargs)
#!python import argparse import batch_notebook if __name__ == '__main__': desc = 'Run IPython notebook scripts in batch mode.' parser = argparse.ArgumentParser(description=desc) parser.add_argument('src', help='source notebook path') parser.add_argument('dst', help='destination notebook path') parser.add_argument('--timeout', '-T', help='max execution time in seconds per cell', type=int) parser.add_argument('--verbose', '-V', action='store_true', help='print status messages as processing proceeds') args = parser.parse_args() kwargs = {} if args.timeout: kwargs['timeout'] = args.timeout if args.verbose: kwargs['verbose'] = args.verbose batch_notebook.run_and_save(args.src, args.dst, **kwargs)