<s> import sys <EOL> import os <EOL> from uuid import uuid4 <EOL> import pymatbridge as pymat <EOL> from pymatbridge . matlab_magic import MatlabInterperterError <EOL> from IPython . testing . globalipapp import get_ipython <EOL> import numpy . testing as npt <EOL> class TestMagic : <EOL> @ classmethod <EOL> def setup_class ( cls ) : <EOL> cls . ip = get_ipython ( ) <EOL> cls . ip . run_cell ( '<STR_LIT>' ) <EOL> cls . ip . run_cell ( '<STR_LIT>' ) <EOL> if '<STR_LIT>' in os . environ : <EOL> matlab = '<STR_LIT>' <EOL> else : <EOL> matlab = '<STR_LIT>' <EOL> socket_addr = "<STR_LIT>" if sys . platform == "<STR_LIT:win32>" else "<STR_LIT>" % str ( uuid4 ( ) ) <EOL> pymat . load_ipython_extension ( cls . ip , matlab = matlab , <EOL> socket_addr = socket_addr ) <EOL> @ classmethod <EOL> def teardown_class ( cls ) : <EOL> pymat . unload_ipython_extension ( cls . ip ) <EOL> def test_cell_magic_number ( self ) : <EOL> self . ip . run_cell ( "<STR_LIT>" ) <EOL> self . ip . run_cell_magic ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> npt . assert_almost_equal ( self . ip . user_ns [ '<STR_LIT:b>' ] , <EOL> self . ip . user_ns [ '<STR_LIT:a>' ] * <NUM_LIT:2> , decimal = <NUM_LIT:7> ) <EOL> def test_cell_magic_number_complex ( self ) : <EOL> self . ip . run_cell ( "<STR_LIT>" ) <EOL> self . ip . run_cell_magic ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . ip . run_cell ( "<STR_LIT>" ) <EOL> npt . assert_almost_equal ( self . ip . user_ns [ '<STR_LIT:y>' ] , <EOL> self . ip . user_ns [ '<STR_LIT>' ] , decimal = <NUM_LIT:7> ) <EOL> def test_cell_magic_array ( self ) : <EOL> self . ip . run_cell ( "<STR_LIT>" ) <EOL> self . ip . run_cell ( "<STR_LIT>" ) <EOL> self . ip . run_cell ( "<STR_LIT>" ) <EOL> self . ip . run_cell_magic ( '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' ) <EOL> npt . assert_almost_equal ( self . ip . user_ns [ '<STR_LIT>' ] , <EOL> self . ip . user_ns [ '<STR_LIT>' ] , decimal = <NUM_LIT:7> ) <EOL> def test_cell_magic_array_complex ( self ) : <EOL> self . ip . run_cell ( "<STR_LIT>" ) <EOL> self . ip . run_cell ( "<STR_LIT>" ) <EOL> self . ip . run_cell ( "<STR_LIT>" ) <EOL> self . ip . run_cell_magic ( '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' ) <EOL> npt . assert_almost_equal ( self . ip . user_ns [ '<STR_LIT>' ] , <EOL> self . ip . user_ns [ '<STR_LIT>' ] , decimal = <NUM_LIT:7> ) <EOL> def test_line_magic ( self ) : <EOL> self . ip . run_line_magic ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . ip . run_line_magic ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . ip . run_cell_magic ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . ip . run_cell ( "<STR_LIT>" ) <EOL> npt . assert_almost_equal ( self . ip . user_ns [ '<STR_LIT>' ] , <EOL> self . ip . user_ns [ '<STR_LIT>' ] , decimal = <NUM_LIT:7> ) <EOL> def test_figure ( self ) : <EOL> self . ip . run_line_magic ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> def test_matrix ( self ) : <EOL> self . ip . run_cell ( "<STR_LIT>" ) <EOL> self . ip . run_cell_magic ( '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' ) <EOL> npt . assert_almost_equal ( self . ip . user_ns [ '<STR_LIT>' ] , <EOL> self . ip . user_ns [ '<STR_LIT>' ] , <EOL> decimal = <NUM_LIT:7> ) <EOL> def test_struct ( self ) : <EOL> self . ip . run_cell ( '<STR_LIT>' ) <EOL> self . ip . run_cell ( '<STR_LIT>' ) <EOL> self . ip . run_cell ( '<STR_LIT>' ) <EOL> self . ip . run_cell_magic ( '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' ) <EOL> npt . assert_equal ( isinstance ( self . ip . user_ns [ '<STR_LIT>' ] , dict ) , True ) <EOL> npt . assert_equal ( self . ip . user_ns [ '<STR_LIT>' ] [ '<STR_LIT>' ] , self . ip . user_ns [ '<STR_LIT>' ] ) <EOL> npt . assert_equal ( self . ip . user_ns [ '<STR_LIT>' ] [ '<STR_LIT>' ] . squeeze ( ) , self . ip . user_ns [ '<STR_LIT>' ] ) <EOL> npt . assert_equal ( self . ip . user_ns [ '<STR_LIT>' ] [ '<STR_LIT:str>' ] , self . ip . user_ns [ '<STR_LIT:str>' ] ) <EOL> def test_faulty ( self ) : <EOL> npt . assert_raises ( MatlabInterperterError , <EOL> lambda : self . ip . run_line_magic ( '<STR_LIT>' , '<STR_LIT>' ) ) </s>
