Revision: 367 http://rpy.svn.sourceforge.net/rpy/?rev=367&view=rev Author: warnes Date: 2007-11-12 22:43:02 -0800 (Mon, 12 Nov 2007)
Log Message: ----------- Select which syntax variant to use by which library was loaded, rather than using try:except to try a second variance after the first failed. Modified Paths: -------------- trunk/rpy/tests/test_numeric.py Modified: trunk/rpy/tests/test_numeric.py =================================================================== --- trunk/rpy/tests/test_numeric.py 2007-11-13 06:27:31 UTC (rev 366) +++ trunk/rpy/tests/test_numeric.py 2007-11-13 06:43:02 UTC (rev 367) @@ -4,9 +4,11 @@ import sys try: from numpy import * + ArrayLib='NumPy' except ImportError: try: from Numeric import * + ArrayLib='Numeric' except ImportError: print '\nNumeric not available. Skipping.\n' sys.exit(0) @@ -83,22 +85,22 @@ # 64 bit ints try: - a = array( [1,2,3], 'Int64' ) - except: - try: + if(ArrayLib=='NumPy'): + a = array( [1,2,3], 'Int64' ) + else: a = array( [1,2,3], Int64 ) - except: - print "\nInt64 Not found. Skipping this test.\n" - return + except: + print "\nInt64 Not found. Skipping this test.\n" + return b = r.c(a) def test32BitIntArray(self): # 32 bit ints - try: + if(ArrayLib=='NumPy'): a = array( [1,2,3], 'Int32' ) - except: + else: a = array( [1,2,3], Int32 ) b = r.c(a) @@ -106,9 +108,9 @@ def test16BitIntArray(self): # 16 bit ints - try: + if(ArrayLib=='NumPy'): a = array( [1,2,3], 'Int16' ) - except: + else: a = array( [1,2,3], Int16 ) b = r.c(a) @@ -116,9 +118,9 @@ def test8BitIntArray(self): # 8 bit ints - try: + if(ArrayLib=='NumPy'): a = array( [1,2,3], 'Int8' ) - except: + else: a = array( [1,2,3], Int8 ) b = r.c(a) @@ -126,9 +128,9 @@ def testBoolArray(self): # 8 bit ints - try: + if(ArrayLib=='NumPy'): a = array( [1,2,3], 'Bool' ) - except: + else: print "Bool arrays not supported by Numeric, skipping" return @@ -138,31 +140,31 @@ # 64 bit ints try: - a = array( [1,2,3], 'Float64' ) - except: - try: + if(ArrayLib=='NumPy'): + a = array( [1,2,3], 'Float64' ) + else: a = array( [1,2,3], Float64 ) - except: - print "Float64 Not found. Skipping this test." - return + except: + print "Float64 Not found. Skipping this test." + return b = r.c(a) def test32BitFloatArray(self): # 32 bit ints - try: + if(ArrayLib=='NumPy'): a = array( [1,2,3], 'Float32' ) - except: + else: a = array( [1,2,3], Float32 ) b = r.c(a) def testCharArray(self): - try: + if(ArrayLib=='NumPy'): a = array( ['A','B', 'C'], character ) - except: + else: a = array( ['A','B', 'C'], Character ) self.failUnlessRaises(RPyTypeConversionException, lambda: r.c(a) ) @@ -170,9 +172,9 @@ def testStringArray(self): - try: + if(ArrayLib=='NumPy'): a = array( ['ABCDEFHIJKLM','B', 'C C C'], 'S10' ) - except: # not available on Numeric + else: # not available on Numeric print "String arrays not supported by Numeric, skipping" return @@ -181,12 +183,12 @@ def testObjArray(self): - try: + if(ArrayLib=='NumPy'): a = array( ['A','B', 'C'], 'object' ) - except: + else: a = array( ['A','B', 'C'], PyObject ) - self.failUnlessRaises(RPyTypeConversionException, lambda: r.c(a) ) + self.failUnlessRaises(RPyTypeConversionException, lambda: r.c(a) ) @@ -194,22 +196,22 @@ # 64 bit ints try: - a = array( [1,2,3], 'Int64' ) - except: - try: + if(ArrayLib=='NumPy'): + a = array( [1,2,3], 'Int64' ) + else: a = array( [1,2,3], Int64 ) - except: - print "\nInt64 Not found. Skipping this test.\n" - return + except: + print "\nInt64 Not found. Skipping this test.\n" + return b = r.c(a[0]) def test32BitIntScalar(self): # 32 bit ints - try: + if(ArrayLib=='NumPy'): a = array( [1,2,3], 'Int32' ) - except: + else: a = array( [1,2,3], Int32 ) b = r.c(a[0]) @@ -217,9 +219,9 @@ def test16BitIntScalar(self): # 16 bit ints - try: + if(ArrayLib=='NumPy'): a = array( [1,2,3], 'Int16' ) - except: + else: a = array( [1,2,3], Int16 ) b = r.c(a[0]) @@ -227,9 +229,9 @@ def test8BitIntScalar(self): # 8 bit ints - try: + if(ArrayLib=='NumPy'): a = array( [1,2,3], 'Int8' ) - except: + else: a = array( [1,2,3], Int8 ) b = r.c(a[0]) @@ -237,9 +239,9 @@ def testBoolScalar(self): # 8 bit ints - try: + if(ArrayLib=='NumPy'): a = array( [1,2,3], 'Bool' ) - except: + else: print "Bool arrays not supported by Numeric, skipping" return @@ -249,31 +251,31 @@ # 64 bit ints try: - a = array( [1,2,3], 'Float64' ) - except: - try: + if(ArrayLib=='NumPy'): + a = array( [1,2,3], 'Float64' ) + else: a = array( [1,2,3], Float64 ) - except: - print "Float64 Not found. Skipping this test." - return + except: + print "Float64 Not found. Skipping this test." + return b = r.c(a[0]) def test32BitFloatScalar(self): # 32 bit ints - try: + if(ArrayLib=='NumPy'): a = array( [1,2,3], 'Float32' ) - except: + else: a = array( [1,2,3], Float32 ) b = r.c(a[0]) def testCharScalar(self): - try: + if(ArrayLib=='NumPy'): a = array( ['A','B', 'C'], character ) - except: + else: a = array( ['A','B', 'C'], Character ) self.failUnless( r.c(a[0])=='A' ) @@ -281,9 +283,9 @@ def testStringScalar(self): - try: + if(ArrayLib=='NumPy'): a = array( ['ABCDEFHIJKLM','B', 'C C C'], 'S10' ) - except: # not available on Numeric + else: # not available on Numeric print "String arrays not supported by Numeric, skipping" return @@ -292,25 +294,14 @@ def testObjScalar(self): - try: + if(ArrayLib=='NumPy'): a = array( ['A','B', 'C'], 'object' ) - except: + else: a = array( ['A','B', 'C'], PyObject ) self.failUnless( r.c(a[0])=='A' ) - - - - - - - - - - - if __name__ == '__main__': unittest.main() This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. ------------------------------------------------------------------------- This SF.net email is sponsored by: Splunk Inc. Still grepping through log files to find problems? Stop. Now Search log events and configuration files using AJAX and a browser. Download your FREE copy of Splunk now >> http://get.splunk.com/ _______________________________________________ rpy-list mailing list rpy-list@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/rpy-list