def testXXXSubtler(self): """test more subtle stuff. This must come last, hence the XXX""" import os, cPickle array = numpy.array # simple strings: assert (mlab._do("''"), mlab._do("'foobar'")) == ('', 'foobar') self.assertEqual(mlab.sort(1), numpy.array([[1.]])) self.assertEqual(mlab.sort([3,1,2]), numpy.array([[1.], [2.], [3.]])) self.assertEqual(mlab.sort(numpy.array([3,1,2])), numpy.array([[1.], [2.], [3.]])) sct = mlab._do("struct('type',{'big','little'},'color','red','x',{3 4})") bct = mlab._do("struct('type',{'BIG','little'},'color','red')") self.assertEqual(sct[1].x, numpy.array([[4]])) self.assertEqual(sct[0].x, numpy.array([[3]])) #FIXME sct[:].x wouldn't work, but currently I'm not sure that's my fault sct[1].x = 'New Value' assert sct[1].x == 'New Value' assert bct[0].type == 'BIG' and sct[0].type == 'big' mlab._set('foo', 1) assert mlab._get('foo') == numpy.array([1.]) assert (mlab._do("{'A', 'b', {3,4, {5,6}}}") != ['A', 'b', [array([[ 3.]]), array([[ 4.]]), [array([[ 5.]]), array([[ 6.]])]]]) mlab._dont_proxy['cell'] = True self.assertEquals(mlab._do("{'a', 'b', {3,4, {5,6}}}"), ['a', 'b', [array([ 3.]), array([ 4.]), [array([ 5.]), array([ 6.])]]]) mlab._dont_proxy['cell'] = False mlab.clear('foo') self.assertRaises(MlabError, mlab._get, 'foo') # XXX: note to self: ``format compact`` in startup.m will cause this # test to fail, but should otherwise be harmless. self.assertEquals(degensym_proxy(repr(sct)), "<MlabObjectProxy of matlab-class: 'struct'; " "internal name: 'PROXY_VAL__'; has parent: no>\n" "1x2 struct array with fields:\n" " type\n color\n x\n\n") #FIXME: add tests for assigning and nesting proxies ## ensure proxies work OK as arguments self.assertEqual(mlab.size(sct), array([[1., 2.]])) self.assertEqual(mlab.size(sct, 1), array([[1]])) # test that exceptions on calls with proxy arguments don't result in # trouble self.assertRaises(MlabError, mlab.svd, sct) self.assertEqual(mlab.size(sct, [2]), array([[2]])) mlab._dont_proxy['cell'] = True gc.collect() assert map(degensym_proxy,without(mlab.who(), WHO_AT_STARTUP)) == ( ['PROXY_VAL__', 'PROXY_VAL__']) # test pickling pickleFilename = mktemp() f = open(pickleFilename, 'wb') try: cPickle.dump({'sct': sct, 'bct': bct},f,1) f.close() f = open(pickleFilename, 'rb') namespace = cPickle.load(f) f.close() finally: os.remove(pickleFilename) gc.collect() assert len(mlab._proxies) == 4, "%d proxies!" % len(mlab._proxies) assert namespace['sct'][1].x == 'New Value' namespace['sct'][1].x = 'Even Newer Value' assert namespace['sct'][1].x == 'Even Newer Value' assert sct[1].x == 'New Value' del sct del bct del namespace['sct'] del namespace['bct'] mlab._set('bar', '1234') x = [] mlab._do("disp 'hallo'" ,nout=0, handle_out=x.append) assert x[0] == 'hallo\n' mlab._dont_proxy['cell'] = False self.assertRaises(ValueError, getattr, mlab, "buggy('ipython lookup')")
def testXXXSubtler(self): """test more subtle stuff. This must come last, hence the XXX""" import os, cPickle array = numpy.array # simple strings: assert (mlab._do("''"), mlab._do("'foobar'")) == ('', 'foobar') self.assertEqual(mlab.sort(1), numpy.array([[1.]])) self.assertEqual(mlab.sort([3, 1, 2]), numpy.array([[1.], [2.], [3.]])) self.assertEqual(mlab.sort(numpy.array([3, 1, 2])), numpy.array([[1.], [2.], [3.]])) sct = mlab._do( "struct('type',{'big','little'},'color','red','x',{3 4})") bct = mlab._do("struct('type',{'BIG','little'},'color','red')") self.assertEqual(sct[1].x, numpy.array([[4]])) self.assertEqual(sct[0].x, numpy.array([[3]])) #FIXME sct[:].x wouldn't work, but currently I'm not sure that's my fault sct[1].x = 'New Value' assert sct[1].x == 'New Value' assert bct[0].type == 'BIG' and sct[0].type == 'big' mlab._set('foo', 1) assert mlab._get('foo') == numpy.array([1.]) assert (mlab._do("{'A', 'b', {3,4, {5,6}}}") != [ 'A', 'b', [array([[3.]]), array([[4.]]), [array([[5.]]), array([[6.]])]] ]) mlab._dont_proxy['cell'] = True self.assertEquals( mlab._do("{'a', 'b', {3,4, {5,6}}}"), ['a', 'b', [array([3.]), array([4.]), [array([5.]), array([6.])]]]) mlab._dont_proxy['cell'] = False mlab.clear('foo') self.assertRaises(MlabError, mlab._get, 'foo') # XXX: note to self: ``format compact`` in startup.m will cause this # test to fail, but should otherwise be harmless. self.assertEquals( degensym_proxy(repr(sct)), "<MlabObjectProxy of matlab-class: 'struct'; " "internal name: 'PROXY_VAL__'; has parent: no>\n" "1x2 struct array with fields:\n" " type\n color\n x\n\n") #FIXME: add tests for assigning and nesting proxies ## ensure proxies work OK as arguments self.assertEqual(mlab.size(sct), array([[1., 2.]])) self.assertEqual(mlab.size(sct, 1), array([[1]])) # test that exceptions on calls with proxy arguments don't result in # trouble self.assertRaises(MlabError, mlab.svd, sct) self.assertEqual(mlab.size(sct, [2]), array([[2]])) mlab._dont_proxy['cell'] = True gc.collect() assert map(degensym_proxy, without(mlab.who(), WHO_AT_STARTUP)) == (['PROXY_VAL__', 'PROXY_VAL__']) # test pickling pickleFilename = mktemp() f = open(pickleFilename, 'wb') try: cPickle.dump({'sct': sct, 'bct': bct}, f, 1) f.close() f = open(pickleFilename, 'rb') namespace = cPickle.load(f) f.close() finally: os.remove(pickleFilename) gc.collect() assert len(mlab._proxies) == 4, "%d proxies!" % len(mlab._proxies) assert namespace['sct'][1].x == 'New Value' namespace['sct'][1].x = 'Even Newer Value' assert namespace['sct'][1].x == 'Even Newer Value' assert sct[1].x == 'New Value' del sct del bct del namespace['sct'] del namespace['bct'] mlab._set('bar', '1234') x = [] mlab._do("disp 'hallo'", nout=0, handle_out=x.append) assert x[0] == 'hallo\n' mlab._dont_proxy['cell'] = False self.assertRaises(ValueError, getattr, mlab, "buggy('ipython lookup')")
TestCase = awmstest.PermeableTestCase2 TestSuite = awmstest.RotatingTestSuite except ImportError: pass from awmstools import indexme, without from mlabwrap import * BUFSIZE=4096 # must be the same as in mlabraw.cpp #XXX for testing in running session with existing mlab ## mlab ## mlab = MlabWrap() mlab._dont_proxy['cell'] = True WHO_AT_STARTUP = mlab.who() mlab._dont_proxy['cell'] = False # FIXME should do this differentlya funnies = without(WHO_AT_STARTUP, ['HOME', 'V', 'WLVERBOSE', 'MLABRAW_ERROR_']) if funnies: print >> sys.stderr, "Hmm, got some funny stuff in matlab env: %s" % funnies #FIXME both below untested def fitString(s, maxCol=79, newlineReplacement="\\n"): if newlineReplacement or isinstance(newlineReplacement, basestring): s = s.replace("\n", newlineReplacement) if maxCol is not None and len(s) > maxCol: s = "%s..." % s[:maxCol-3] return s class NumericTestCase(TestCase): """Simple extensio to TestCase to handle array equality tests 'correctly' (i.e. work around rich comparisons). Since array repr's can also be very large, the printing of large reprs is controlled by ``maxReprLength`` (None to print everything) and
except ImportError: pass from awmstools import indexme, without from mlabwrap import * BUFSIZE = 4096 # must be the same as in mlabraw.cpp #XXX for testing in running session with existing mlab ## mlab ## mlab = MlabWrap() mlab._dont_proxy['cell'] = True WHO_AT_STARTUP = mlab.who() mlab._dont_proxy['cell'] = False # FIXME should do this differentlya funnies = without(WHO_AT_STARTUP, ['HOME', 'V', 'WLVERBOSE', 'MLABRAW_ERROR_']) if funnies: print >> sys.stderr, "Hmm, got some funny stuff in matlab env: %s" % funnies #FIXME both below untested def fitString(s, maxCol=79, newlineReplacement="\\n"): if newlineReplacement or isinstance(newlineReplacement, basestring): s = s.replace("\n", newlineReplacement) if maxCol is not None and len(s) > maxCol: s = "%s..." % s[:maxCol - 3] return s class NumericTestCase(TestCase): """Simple extensio to TestCase to handle array equality tests 'correctly'