How to use the sos.jupyter.test_utils.sos_kernel function in sos

To help you get started, we’ve selected a few sos examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github vatlab / sos / test / jupyter / test_sos_magics.py View on Github external
def testVisualizer(self):
        with sos_kernel() as kc:
            # preview variable
            iopub = kc.iopub_channel
            # preview dataframe
            execute(kc=kc, code='''
%preview mtcars -n -l 10
%get mtcars --from R
''')
            res = get_display_data(iopub, 'text/html')
            self.assertTrue('dataframe_container' in res and 'Mazda' in res, 'Expect preview {}'.format(res))
            #
            execute(kc=kc, code='''
%preview mtcars -n -s scatterplot mpg disp --by cyl
%get mtcars --from R
''')
            res = get_display_data(iopub, 'text/html')
            self.assertTrue('Hornet' in res, 'Expect preview {}'.format(res))
github vatlab / sos / test / jupyter / test_sos_kernel.py View on Github external
def testInterpolation(self):
        with sos_kernel() as kc:
            iopub = kc.iopub_channel
            execute(kc=kc, code='print("a=${100+11}")')
            stdout, stderr = assemble_output(iopub)
            self.assertTrue(stdout.endswith('a=111\n'))
            self.assertEqual(stderr, '')
github vatlab / sos / test / JavaScript / test_JavaScript_kernel.py View on Github external
def testGetPythonDataFrameFromJavaScript(self):
        # Python -> R
        with sos_kernel() as kc:
            iopub = kc.iopub_channel
            # create a data frame
            execute(kc=kc, code='''
import pandas as pd
import numpy as np
arr = np.random.randn(1000)
arr[::10] = np.nan
df = pd.DataFrame({'column_{0}'.format(i): arr for i in range(10)})
''')
            clear_channels(iopub)
            execute(kc=kc, code="%use JavaScript")
            wait_for_idle(kc)
            execute(kc=kc, code="%get df")
            wait_for_idle(kc)
            execute(kc=kc, code="Object.keys(df).length")
            res = get_display_data(iopub)
github vatlab / sos / test / Bash / test_Bash_kernel.py View on Github external
def testGetDataFromBash(self):
        with sos_kernel() as kc:
            iopub = kc.iopub_channel
            execute(kc=kc, code='''
null_var = None
num_var = 123
logic_var = True
char_var = '123'
char_arr_var = ['1', '2', '3']
list_var = [1, 2, '3']
dict_var = dict(a=1, b=2, c='3')
set_var = {1, 2, '3'}
''')
            wait_for_idle(kc)
            execute(kc=kc, code='''
%use Bash
%get null_var num_var logic_var char_var char_arr_var list_var dict_var set_var
%dict -r
github vatlab / sos / test / jupyter / test_sos_magics.py View on Github external
def testMagicDebug(self):
        with sos_kernel() as kc:
            # preview variable
            execute(kc=kc, code='''
%debug on
%debug off
''')
            wait_for_idle(kc)
github vatlab / sos / test / jupyter / test_sos_inspector.py View on Github external
def testIsComplete(self):
        with sos_kernel() as kc:
            # match magics
            status = is_complete(kc, 'prin')
            self.assertEqual(status['status'], 'incomplete')
            #
            status = is_complete(kc, 'a=1')
            self.assertEqual(status['status'], 'incomplete')
            #
            status = is_complete(kc, '')
            self.assertEqual(status['status'], 'complete')
            #
            status = is_complete(kc, 'input:\n a=1,')
            self.assertEqual(status['status'], 'incomplete')
            #
            status = is_complete(kc, '%dict -r')
            self.assertEqual(status['status'], 'complete')
            wait_for_idle(kc)
github vatlab / sos / test / jupyter / test_sos_kernel.py View on Github external
def testMagicDict(self):
        '''Test %dict magic'''
        with sos_kernel() as kc:
            iopub = kc.iopub_channel
            execute(kc=kc, code="a=12345")
            wait_for_idle(kc)
            execute(kc=kc, code="%dict a")
            self.assertEqual(get_result(iopub)['a'], 12345)
            execute(kc=kc, code="%dict --keys")
            self.assertTrue('a' in get_result(iopub))
            execute(kc=kc, code="%dict --reset")
            wait_for_idle(kc)
            execute(kc=kc, code="%dict --keys --all")
            res = get_result(iopub)
            self.assertTrue('a' not in res)
            for key in ('run', 'sh', 'tcsh', 'expand_pattern'):
                self.assertTrue(key in res)
github vatlab / sos / test / jupyter / test_sos_kernel.py View on Github external
def testMagicDict(self):
        '''Test %dict magic'''
        with sos_kernel() as kc:
            iopub = kc.iopub_channel
            execute(kc=kc, code="a=12345")
            wait_for_idle(kc)
            execute(kc=kc, code="%dict a")
            self.assertEqual(get_result(iopub)['a'], 12345)
            execute(kc=kc, code="%dict --keys")
            self.assertTrue('a' in get_result(iopub))
            execute(kc=kc, code="%dict --reset")
            wait_for_idle(kc)
            execute(kc=kc, code="%dict --keys --all")
            res = get_result(iopub)
            self.assertTrue('a' not in res)
            for key in ('run', 'sh', 'tcsh', 'expand_pattern'):
                self.assertTrue(key in res)
github vatlab / sos / test / jupyter / test_sos_magics.py View on Github external
def testMagicSet(self):
        # test preview of remote file
        with sos_kernel() as kc:
            iopub = kc.iopub_channel
            # preview variable
            execute(kc=kc, code='''
%set
%set -v2
%set
%set -v1
''')
        stdout, stderr = assemble_output(iopub)
        self.assertEqual(stderr, '', 'Got {}'.format(stderr))
        self.assertTrue('set' in stdout, 'Got {}'.format(stdout))
github vatlab / sos / test / jupyter / test_sos_magics.py View on Github external
def testMagicSave(self):
        with sos_kernel() as kc:
            if os.path.isfile('test.txt'):
                os.remove('test.txt')
            execute(kc=kc, code='''
%preview ~/test.txt
%save ~/test.txt
a=1
''')
            wait_for_idle(kc)
            with open(os.path.join(os.path.expanduser('~'), 'test.txt')) as tt:
                self.assertEqual(tt.read(), 'a=1\n')