# Test that sos kernel is installed

import jupyter_client

try:
    print(jupyter_client.kernelspec.get_kernel_spec('sos').to_dict())
except jupyter_client.kernelspec.NoSuchKernel:
    print('sos kernel was not installed')
    print('The following kernels are installed:')
    print('jupyter_client.kernelspec.find_kernel_specs()')
    print(jupyter_client.kernelspec.find_kernel_specs())

# Test that sos kernel is functional

import unittest

from sos_notebook.test_utils import sos_kernel
from ipykernel.tests.utils import execute, wait_for_idle, assemble_output

class TestSoSKernel(unittest.TestCase):
    def testKernel(self):
        with sos_kernel() as kc:
            execute(kc=kc, code='a = 1\nprint(a)')
            stdout, stderr = assemble_output(kc.get_iopub_msg)
            self.assertEqual(stdout.strip(), '1')

if __name__ == '__main__':
    unittest.main()
