本文整理汇总了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)