/
utils.py
29 lines (24 loc) · 924 Bytes
/
utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# AUTOGENERATED! DO NOT EDIT! File to edit: ../nbs/00_utils.ipynb.
# %% auto 0
__all__ = ['get_output', 'capture_cmd_output', 'test_md_output']
# %% ../nbs/00_utils.ipynb 2
from fastcore.test import test_eq, test_fail
from IPython.utils.capture import capture_output
# %% ../nbs/00_utils.ipynb 4
def get_output(func, *args, **kwargs):
with capture_output() as captured:
func(*args, **kwargs)
got = captured._outputs[0]["data"].get("text/markdown")
return got
# %% ../nbs/00_utils.ipynb 5
def capture_cmd_output(cmd):
with capture_output() as captured:
eval(cmd)
return captured
# %% ../nbs/00_utils.ipynb 7
def test_md_output(func, expected, *args, **kwargs):
with capture_output() as captured:
func(*args, **kwargs)
got = captured._outputs[0]["data"].get("text/markdown")
assert got is not None, "No markdown output found"
test_eq(got, expected)