# Path: metakernel/tests/utils.py
# def get_kernel(kernel_class=MetaKernel):
#     context = zmq.Context.instance()
#     iopub_socket = context.socket(zmq.PUB)
# 
#     kernel = kernel_class(session=ss.Session(), iopub_socket=iopub_socket,
#                           log=get_log())
#     return kernel
# 
# def get_log_text(obj):
#     """Get the log text from a kernel or a log object."""
#     if isinstance(obj, MetaKernel):
#         log = obj.log
#     else:
#         log = obj
#     return log.handlers[0].stream.getvalue()
# 
# def clear_log_text(obj):
#     """Clear the log text from a kernel or a log object."""
#     if isinstance(obj, MetaKernel):
#         log = obj.log
#     else:
#         log = obj
#     log.handlers[0].stream.truncate(0)
#     log.handlers[0].stream.seek(0)


import textwrap
from metakernel.tests.utils import get_kernel, get_log_text, clear_log_text

    text = '%python imp'
    comp = kernel.do_complete(text, len(text))

    assert 'import' in comp['matches']

    helpstr = kernel.get_help_on('%python bin')
    assert 'Return the binary representation of an integer' in helpstr, helpstr


def test_python_magic2():
    kernel = get_kernel()
    kernel.do_execute('%python retval = 1', None)
    assert '1' in get_log_text(kernel)

    kernel.do_execute(textwrap.dedent('''\
    %%python
    def test(a):
        return a + 1
    retval = test(2)'''), None)
    assert '3' in get_log_text(kernel)

    kernel.do_execute(textwrap.dedent('''\
    %%python
    def test(a):
        return a + 1
    test(2)'''), None)
    assert '3' in get_log_text(kernel)

def test_python_magic3():

# Path: metakernel/tests/utils.py
# def get_kernel(kernel_class=MetaKernel):
#     context = zmq.Context.instance()
#     iopub_socket = context.socket(zmq.PUB)
# 
#     kernel = kernel_class(session=ss.Session(), iopub_socket=iopub_socket,
#                           log=get_log())
#     return kernel
# 
# def get_log_text(obj):
#     """Get the log text from a kernel or a log object."""
#     if isinstance(obj, MetaKernel):
#         log = obj.log
#     else:
#         log = obj
#     return log.handlers[0].stream.getvalue()
# 
# def clear_log_text(obj):
#     """Clear the log text from a kernel or a log object."""
#     if isinstance(obj, MetaKernel):
#         log = obj.log
#     else:
#         log = obj
#     log.handlers[0].stream.truncate(0)
#     log.handlers[0].stream.seek(0)


# Path: metakernel/magics/tests/test_python_magic.py
import textwrap
from metakernel.tests.utils import get_kernel, get_log_text, clear_log_text


    text = '%python imp'
    comp = kernel.do_complete(text, len(text))

    assert 'import' in comp['matches']

    helpstr = kernel.get_help_on('%python bin')
    assert 'Return the binary representation of an integer' in helpstr, helpstr


def test_python_magic2():
    kernel = get_kernel()
    kernel.do_execute('%python retval = 1', None)
    assert '1' in get_log_text(kernel)

    kernel.do_execute(textwrap.dedent('''\
    %%python
    def test(a):
        return a + 1
    retval = test(2)'''), None)
    assert '3' in get_log_text(kernel)

    kernel.do_execute(textwrap.dedent('''\
    %%python
    def test(a):
        return a + 1
    test(2)'''), None)
    assert '3' in get_log_text(kernel)

def test_python_magic3():

    kernel = get_kernel()