本文整理匯總了Python中nbconvert.preprocessors.CellExecutionError方法的典型用法代碼示例。如果您正苦於以下問題:Python preprocessors.CellExecutionError方法的具體用法?Python preprocessors.CellExecutionError怎麽用?Python preprocessors.CellExecutionError使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類nbconvert.preprocessors
的用法示例。
在下文中一共展示了preprocessors.CellExecutionError方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_timeseries_controls
# 需要導入模塊: from nbconvert import preprocessors [as 別名]
# 或者: from nbconvert.preprocessors import CellExecutionError [as 別名]
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
示例2: test_clustering_nbdisplay_notebook
# 需要導入模塊: from nbconvert import preprocessors [as 別名]
# 或者: from nbconvert.preprocessors import CellExecutionError [as 別名]
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
示例3: test_process_tree_notebook
# 需要導入模塊: from nbconvert import preprocessors [as 別名]
# 或者: from nbconvert.preprocessors import CellExecutionError [as 別名]
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
示例4: test_geoip_notebook
# 需要導入模塊: from nbconvert import preprocessors [as 別名]
# 或者: from nbconvert.preprocessors import CellExecutionError [as 別名]
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
示例5: test_timeline_controls
# 需要導入模塊: from nbconvert import preprocessors [as 別名]
# 或者: from nbconvert.preprocessors import CellExecutionError [as 別名]
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
示例6: test_widgets_notebook
# 需要導入模塊: from nbconvert import preprocessors [as 別名]
# 或者: from nbconvert.preprocessors import CellExecutionError [as 別名]
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
示例7: f
# 需要導入模塊: from nbconvert import preprocessors [as 別名]
# 或者: from nbconvert.preprocessors import CellExecutionError [as 別名]
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
示例8: test_failed_execution
# 需要導入模塊: from nbconvert import preprocessors [as 別名]
# 或者: from nbconvert.preprocessors import CellExecutionError [as 別名]
def test_failed_execution():
with pytest.raises(CellExecutionError) as exc_info:
_run('resources/runtime_error.ipynb')
assert 'ZeroDivisionError' in exc_info.value.traceback
示例9: run_tests
# 需要導入模塊: from nbconvert import preprocessors [as 別名]
# 或者: from nbconvert.preprocessors import CellExecutionError [as 別名]
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)
示例10: execute_test
# 需要導入模塊: from nbconvert import preprocessors [as 別名]
# 或者: from nbconvert.preprocessors import CellExecutionError [as 別名]
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)
示例11: test
# 需要導入模塊: from nbconvert import preprocessors [as 別名]
# 或者: from nbconvert.preprocessors import CellExecutionError [as 別名]
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)