# 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()
# 
# Path: metakernel/process_metakernel.py
# class BashKernel(ProcessMetaKernel):
#     # Identifiers:
#     implementation = 'bash_kernel'
#     language = 'bash'
#     language_info = {
#         'mimetype': 'text/x-bash',
#         'language': 'bash',
#         # ------ If different from 'language':
#         # 'codemirror_mode': 'language',
#         # 'pygments_lexer': 'language',
#         'file_extension': 'sh',
#     }
# 
#     _banner = None
#     @property
#     def banner(self):
#         if self._banner is None:
#             self._banner = check_output(['bash', '--version']).decode('utf-8')
#         return self._banner
# 
#     def makeWrapper(self):
#         return bash()


from IPython.display import HTML
from metakernel.tests.utils import get_kernel, get_log_text
from metakernel.process_metakernel import BashKernel




def test_process_metakernel():
    kernel = get_kernel(BashKernel)
    kernel.do_execute("cat \"%s\"" % __file__, False)
    log_text = get_log_text(kernel)
    assert 'metakernel.py' in log_text, log_text

    kernel.do_execute('echo "hello"\necho "goodbye"', None)
    log_text = get_log_text(kernel)
    assert '"hello"' in log_text
    assert '"goodbye"' in log_text

    kernel.do_execute('lalkjds')
    text = get_log_text(kernel)
    assert ': command not found' in text, text

    html = HTML("some html")
    kernel.Display(html)

    kernel.do_execute(r'for i in {1..3};do echo -ne "$i\r"; sleep 1; done', 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()
# 
# Path: metakernel/process_metakernel.py
# class BashKernel(ProcessMetaKernel):
#     # Identifiers:
#     implementation = 'bash_kernel'
#     language = 'bash'
#     language_info = {
#         'mimetype': 'text/x-bash',
#         'language': 'bash',
#         # ------ If different from 'language':
#         # 'codemirror_mode': 'language',
#         # 'pygments_lexer': 'language',
#         'file_extension': 'sh',
#     }
# 
#     _banner = None
#     @property
#     def banner(self):
#         if self._banner is None:
#             self._banner = check_output(['bash', '--version']).decode('utf-8')
#         return self._banner
# 
#     def makeWrapper(self):
#         return bash()


# Path: metakernel/tests/test_process_metakernel.py
from IPython.display import HTML
from metakernel.tests.utils import get_kernel, get_log_text
from metakernel.process_metakernel import BashKernel





def test_process_metakernel():
    kernel = get_kernel(BashKernel)
    kernel.do_execute("cat \"%s\"" % __file__, False)
    log_text = get_log_text(kernel)
    assert 'metakernel.py' in log_text, log_text

    kernel.do_execute('echo "hello"\necho "goodbye"', None)
    log_text = get_log_text(kernel)
    assert '"hello"' in log_text
    assert '"goodbye"' in log_text

    kernel.do_execute('lalkjds')
    text = get_log_text(kernel)
    assert ': command not found' in text, text

    html = HTML("some html")
    kernel.Display(html)

    kernel.do_execute(r'for i in {1..3};do echo -ne "$i\r"; sleep 1; done', None)

    text = get_log_text(kernel)