<commit_before>import unittest
import sys
import os
import subprocess
import nbformat
from nbconvert.preprocessors import ClearOutputPreprocessor, ExecutePreprocessor


# Testing for the notebooks - use nbconvert to execute all cells of the
# notebook

# add names of notebooks to ignore here.
py2Ignore = []

TESTDIR = os.path.abspath(__file__)
NBDIR = os.path.sep.join(TESTDIR.split(os.path.sep)[:-3] + ['em_apps/']) # where are the notebooks?


def setUp():
    nbpaths = []  # list of notebooks, with file paths
    nbnames = []  # list of notebook names (for making the tests)

    # walk the test directory and find all notebooks
    for dirname, dirnames, filenames in os.walk(NBDIR):
        for filename in filenames:
            if filename.endswith(".ipynb") and not filename.endswith("-checkpoint.ipynb"):
                nbpaths.append(os.path.abspath(dirname) + os.path.sep + filename) # get abspath of notebook
                nbnames.append("".join(filename[:-6])) # strip off the file extension
    return nbpaths, nbnames


def get(nbname, nbpath):

    # use nbconvert to execute the notebook
    def test_func(self):
        print("\n--------------- Testing {0} ---------------".format(nbname))
        print("   {0}".format(nbpath))

        if nbname in py2Ignore and sys.version_info[0] == 2:
            print(" Skipping {}".format(nbname))
            return

        ep = ClearOutputPreprocessor()

        with open(nbpath) as f:
            nb = nbformat.read(f, as_version=4)

            ep.preprocess(nb, {})

            ex = ExecutePreprocessor(
                timeout=600,
                kernel_name='python{}'.format(sys.version_info[0]),
                # {}
            )

            try:
                out = ex.preprocess(nb, {})
            except CellExecutionError:
                print("\n <<<<< {0} FAILED >>>>> \n".format(nbname))
                print("Captured Output: \n")<commit_msg>import CellExecutionError from the right place<commit_after>import unittest
import sys
import os
import subprocess
import nbformat
from nbconvert.preprocessors import ClearOutputPreprocessor, ExecutePreprocessor
from nbconvert.preprocessors.execute import CellExecutionError


# Testing for the notebooks - use nbconvert to execute all cells of the
# notebook

# add names of notebooks to ignore here.
py2Ignore = []

TESTDIR = os.path.abspath(__file__)
NBDIR = os.path.sep.join(TESTDIR.split(os.path.sep)[:-3] + ['em_apps/']) # where are the notebooks?


def setUp():
    nbpaths = []  # list of notebooks, with file paths
    nbnames = []  # list of notebook names (for making the tests)

    # walk the test directory and find all notebooks
    for dirname, dirnames, filenames in os.walk(NBDIR):
        for filename in filenames:
            if filename.endswith(".ipynb") and not filename.endswith("-checkpoint.ipynb"):
                nbpaths.append(os.path.abspath(dirname) + os.path.sep + filename) # get abspath of notebook
                nbnames.append("".join(filename[:-6])) # strip off the file extension
    return nbpaths, nbnames


def get(nbname, nbpath):

    # use nbconvert to execute the notebook
    def test_func(self):
        print("\n--------------- Testing {0} ---------------".format(nbname))
        print("   {0}".format(nbpath))

        if nbname in py2Ignore and sys.version_info[0] == 2:
            print(" Skipping {}".format(nbname))
            return

        ep = ClearOutputPreprocessor()

        with open(nbpath) as f:
            nb = nbformat.read(f, as_version=4)

            ep.preprocess(nb, {})

            ex = ExecutePreprocessor(
                timeout=600,
                kernel_name='python{}'.format(sys.version_info[0]),
            )

            try:
                out = ex.preprocess(nb, {})
            except CellExecutionError:
                print("\n <<<<< {0} FAILED >>>>> \n".format(nbname))
                print("Captured Output: \n")
{'fraction_non_alphanumeric': 0.12585464674601166, 'fraction_numerical': 0.007090402633578121, 'mean_word_length': 2.353140916808149, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3914758', 'n_tokens_mistral': 1202, 'n_tokens_neox': 1146, 'n_words': 320}