Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up and doc the test.runWith*() functions #122

Open
ceball opened this issue May 20, 2020 · 1 comment
Open

Clean up and doc the test.runWith*() functions #122

ceball opened this issue May 20, 2020 · 1 comment
Labels
part: cell tests Relating to cell testing component

Comments

@ceball
Copy link
Collaborator

ceball commented May 20, 2020

def run(notebook, rules=None, filename=None):
    nb = nbformat.read(notebook, 4)
    name = filename or notebook[:-6] + '_test.py'  # remove .ipynb, replace with _test.py
    [... generate test file...]
    return name
def runWithReturn(notebook, executable=None, rules=None):
    name = run([...])
    executable = executable or [sys.executable, '-m', 'pytest', '-v']
    argv = executable + [name]
    return subprocess.check_output(argv)
def runWithReport(notebook, executable=None, rules=None, collect_only=False):
    tmpd = tempfile.mkdtemp()
    py_file = os.path.join(tmpd, os.path.basename(notebook).replace('.ipynb', '.py'))
    json_file = os.path.join(tmpd, os.path.basename(notebook).replace('.ipynb', '.json'))
    _ = run(notebook, filename=py_file, rules=rules)
    ret = []
    [...run with ?coverage and collect results - TODO: read this code and see...]
    return ret
def runWithHTMLReturn(notebook, executable=None, rules=None):
    '''use pytest self contained html'''
    name = run(notebook, rules=rules)
    html = name.replace('.py', '.html')
    executable = executable or [sys.executable, '-m', 'pytest', '-v']
    argv = executable + ['--html=' + html, '--self-contained-html', name]
    subprocess.call(argv)
    with open(html, 'r', encoding='utf-8') as fp:
        return fp.read()
def runWithHTMLReturn2(notebook, executable=None, rules=None):
    '''use custom return objects'''
    ret = ''
    executable = executable or [sys.executable, '-m', 'pytest', '-v']
    ret_tmp = run(notebook, rules=rules)
    for test in ret_tmp:
        test = test.to_html()
        ret += '<p>' + test + '</p>'
    return '<div style="display: flex; flex-direction: column;">' + test + '</div>'
@ceball ceball changed the title Clean up and doc the test.report*() functions Clean up and doc the test.runWith*() functions May 20, 2020
@ceball ceball added the part: cell tests Relating to cell testing component label May 20, 2020
@ceball
Copy link
Collaborator Author

ceball commented May 20, 2020

Notes:

python -m nbcelltests.test ... does not actually use any of the run functions, but most likely should.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
part: cell tests Relating to cell testing component
Projects
None yet
Development

No branches or pull requests

1 participant