Python nbconvert.preprocessors.CellExecutionError() Examples
The following are 12
code examples of nbconvert.preprocessors.CellExecutionError().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
nbconvert.preprocessors
, or try the search function
.
Example #1
Source File: test_timeseries.py From msticpy with MIT License | 8 votes |
def test_timeseries_controls(self): nb_path = Path(_NB_FOLDER).joinpath(_NB_NAME) abs_path = Path(_NB_FOLDER).absolute() with open(nb_path) as f: nb = nbformat.read(f, as_version=4) ep = ExecutePreprocessor(timeout=600, kernel_name="python3") try: ep.preprocess(nb, {"metadata": {"path": abs_path}}) except CellExecutionError: nb_err = str(nb_path).replace(".ipynb", "-err.ipynb") msg = f"Error executing the notebook '{nb_path}'.\n" msg += f"See notebook '{nb_err}' for the traceback." print(msg) with open(nb_err, mode="w", encoding="utf-8") as f: nbformat.write(nb, f) raise
Example #2
Source File: test_nbdisplay.py From msticpy with MIT License | 6 votes |
def test_clustering_nbdisplay_notebook(self): nb_path = Path(_NB_FOLDER).joinpath(_NB_NAME) abs_path = Path(_NB_FOLDER).absolute() with open(nb_path) as f: nb = nbformat.read(f, as_version=4) ep = ExecutePreprocessor(timeout=600, kernel_name="python3") try: ep.preprocess(nb, {"metadata": {"path": abs_path}}) except CellExecutionError: nb_err = str(nb_path).replace(".ipynb", "-err.ipynb") msg = f"Error executing the notebook '{nb_path}'.\n" msg += f"See notebook '{nb_err}' for the traceback." print(msg) with open(nb_err, mode="w", encoding="utf-8") as f: nbformat.write(nb, f) raise
Example #3
Source File: test_process_tree_utils.py From msticpy with MIT License | 6 votes |
def test_process_tree_notebook(): nb_path = Path(_NB_FOLDER).joinpath(_NB_NAME) abs_path = Path(_NB_FOLDER).absolute() with open(nb_path) as f: nb = nbformat.read(f, as_version=4) ep = ExecutePreprocessor(timeout=600, kernel_name="python3") try: ep.preprocess(nb, {"metadata": {"path": abs_path}}) except CellExecutionError: nb_err = str(nb_path).replace(".ipynb", "-err.ipynb") msg = f"Error executing the notebook '{nb_path}'.\n" msg += f"See notebook '{nb_err}' for the traceback." print(msg) with open(nb_err, mode="w", encoding="utf-8") as f: nbformat.write(nb, f) raise
Example #4
Source File: test_geoip.py From msticpy with MIT License | 6 votes |
def test_geoip_notebook(self): nb_path = Path(_NB_FOLDER).joinpath(_NB_NAME) abs_path = Path(_NB_FOLDER).absolute() with open(nb_path, "rb") as f: nb_bytes = f.read() nb_text = nb_bytes.decode("utf-8") nb = nbformat.reads(nb_text, as_version=4) ep = ExecutePreprocessor(timeout=600, kernel_name="python3") try: ep.preprocess(nb, {"metadata": {"path": abs_path}}) except CellExecutionError: nb_err = str(nb_path).replace(".ipynb", "-err.ipynb") msg = f"Error executing the notebook '{nb_path}'.\n" msg += f"See notebook '{nb_err}' for the traceback." print(msg) with open(nb_err, mode="w", encoding="utf-8") as f: nbformat.write(nb, f) raise
Example #5
Source File: test_timeline.py From msticpy with MIT License | 6 votes |
def test_timeline_controls(self): nb_path = Path(_NB_FOLDER).joinpath(_NB_NAME) abs_path = Path(_NB_FOLDER).absolute() with open(nb_path) as f: nb = nbformat.read(f, as_version=4) ep = ExecutePreprocessor(timeout=600, kernel_name="python3") try: ep.preprocess(nb, {"metadata": {"path": abs_path}}) except CellExecutionError: nb_err = str(nb_path).replace(".ipynb", "-err.ipynb") msg = f"Error executing the notebook '{nb_path}'.\n" msg += f"See notebook '{nb_err}' for the traceback." print(msg) with open(nb_err, mode="w", encoding="utf-8") as f: nbformat.write(nb, f) raise
Example #6
Source File: test_nbwidgets.py From msticpy with MIT License | 6 votes |
def test_widgets_notebook(self): nb_path = Path(_NB_FOLDER).joinpath(_NB_NAME) abs_path = Path(_NB_FOLDER).absolute() with open(nb_path) as f: nb = nbformat.read(f, as_version=4) ep = ExecutePreprocessor(timeout=600, kernel_name="python3") try: ep.preprocess(nb, {"metadata": {"path": abs_path}}) except CellExecutionError: nb_err = str(nb_path).replace(".ipynb", "-err.ipynb") msg = f"Error executing the notebook '{nb_path}'.\n" msg += f"See notebook '{nb_err}' for the traceback." print(msg) with open(nb_err, mode="w", encoding="utf-8") as f: nbformat.write(nb, f) raise
Example #7
Source File: test_notebooks_getting_started.py From Grid2Op with Mozilla Public License 2.0 | 5 votes |
def f(self): with open(notebook_filename) as f: nb = nbformat.read(f, as_version=4) ep = ExecutePreprocessor(timeout=600) try: ep.preprocess(nb, {'metadata': {'path': path_save_notebook}}) except CellExecutionError: raise
Example #8
Source File: test_notebooks_getting_started.py From Grid2Op with Mozilla Public License 2.0 | 5 votes |
def f(self): with open(notebook_filename) as f: nb = nbformat.read(f, as_version=4) ep = ExecutePreprocessor(timeout=600) try: ep.preprocess(nb, {'metadata': {'path': path_save_notebook}}) except CellExecutionError: raise
Example #9
Source File: test_execution.py From treon with MIT License | 5 votes |
def test_failed_execution(): with pytest.raises(CellExecutionError) as exc_info: _run('resources/runtime_error.ipynb') assert 'ZeroDivisionError' in exc_info.value.traceback
Example #10
Source File: task.py From treon with MIT License | 5 votes |
def run_tests(self): LOG.info("Triggered test for %s", self.file_path) try: self.is_successful, console_output = execute_notebook(self.file_path) result = self.result_string() if not self.is_successful or _is_verbose(): result += console_output LOG.info(result) except CellExecutionError as cell_error: LOG.error(self.error_string(cell_error.traceback)) except ConversionException: LOG.exception("Execution of notebook '%s' failed", self.file_path)
Example #11
Source File: test_colabs.py From agents with Apache License 2.0 | 5 votes |
def execute_test(file_path, result_path): """Executes a single notebook. Args: file_path: Path to the notebook to execute. result_path: Path to store the resulting notebook. Returns: bool: True if the notebook does not have any errors, False otherwise. Raises: Exception if an unexpected error occurs executing the notebook. """ try: with open(file_path, 'r') as f: filedata = f.read() if FLAGS.override_pip_install_agents: filedata = filedata.replace('pip install tf-agents', 'pip --version') nb = nbformat.reads(filedata, as_version=4) ep = ExecutePreprocessor(timeout=3600, kernel_name='python3') try: ep.preprocess(nb, {'metadata': {'path': FLAGS.output_dir}}) except CellExecutionError as cex: logging.error('ERROR executing:%s', file_path) logging.error(cex) return False with open(result_path, 'w', encoding='utf-8') as fo: nbformat.write(nb, fo) return True except Exception as e: # pylint: disable=W0703 logging.error('Unexpected ERROR: in %s', file_path) logging.error(e)
Example #12
Source File: test_docs.py From pymoo with Apache License 2.0 | 4 votes |
def test(self): PYMOO_DIR = get_pymoo() DOC_DIR = os.path.join(PYMOO_DIR, "doc", "source") ipynb = [] # collect all the jupyter ipynb in the documentation for root, directories, filenames in os.walk(DOC_DIR): for filename in filenames: if filename.endswith(".ipynb") and "checkpoint" not in filename and not any([filename in s for s in SKIP]): ipynb.append(os.path.join(root, filename)) i = 0 if STARTING_AT is not None: for j in range(len(ipynb)): if STARTING_AT not in ipynb[j]: i += 1 else: break ep = ExecutePreprocessor(timeout=10000, kernel_name='python3') for i in range(i, len(ipynb)): fname = ipynb[i] print(fname.split("/")[-1]) import warnings warnings.filterwarnings("ignore") try: nb = nbformat.read(fname, nbformat.NO_CONVERT) ep.preprocess(nb, {'metadata': {'path': PYMOO_DIR}}) except CellExecutionError: msg = 'Error executing the fname "%s".\n\n' % fname print(msg) raise finally: if OVERWRITE: with open(fname, mode='wt') as f: nbformat.write(nb, f)