# 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)


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



def test_help_magic():
    kernel = get_kernel()
    kernel.do_execute('?%magic', None)
    text = get_log_text(kernel)
    assert '%magic - show installed magics' in text, repr(text)

    kernel.do_execute('%lsmagic??', None)
    text = get_log_text(kernel)
    assert 'class LSMagicMagic' in text

    kernel.do_execute('?', None)
    text = get_log_text(kernel)
    assert 'This is a usage statement.' in text

    kernel.do_execute('?%', None)

# 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_help_magic.py
from metakernel.tests.utils import get_kernel, get_log_text, clear_log_text




def test_help_magic():
    kernel = get_kernel()
    kernel.do_execute('?%magic', None)
    text = get_log_text(kernel)
    assert '%magic - show installed magics' in text, repr(text)

    kernel.do_execute('%lsmagic??', None)
    text = get_log_text(kernel)
    assert 'class LSMagicMagic' in text

    kernel.do_execute('?', None)
    text = get_log_text(kernel)
    assert 'This is a usage statement.' in text

    kernel.do_execute('?%', None)

    text = get_log_text(kernel)