from unit_timeside import *
from timeside.analyzer.core import *
+from numpy import ones, array
+from math import pi
verbose = 0
"list of lists result"
self.result.value = [[0,1], [0,1,2]]
+ def testOnNumpyVectorOfFloat(self):
+ "numpy vector of float"
+ self.result.value = ones(2, dtype = 'float') * pi
+
+ def testOnNumpy2DArrayOfFloat64(self):
+ "numpy 2d array of float64"
+ self.result.value = ones([2,3], dtype = 'float64') * pi
+
+ def testOnNumpy3DArrayOfInt32(self):
+ "numpy 3d array of int32"
+ self.result.value = ones([2,3,2], dtype = 'int32') * pi
+
+ def testOnNumpyArrayOfStrings(self):
+ "numpy array of strings"
+ self.result.value = array(['hello', 'hola'])
+
+ def testOnEmptyList(self):
+ "empty list"
+ self.result.value = []
+
+ def testOnNone(self):
+ "None"
+ self.result.value = None
+
+ def testOnUnicode(self):
+ "None"
+ self.result.value = None
+
def tearDown(self):
pass
+good_numpy_data_types = [
+ 'float64',
+ 'float32',
+ 'float16',
+ 'int64',
+ 'int16',
+ 'int32',
+ 'int8',
+ 'uint16',
+ 'uint32',
+ 'uint64',
+ 'uint8',
+]
+
+bad_numpy_data_types = [
+ # not understood by json or yaml
+ 'float128',
+ # complex can not be serialized in json
+ 'complex256',
+ 'complex128',
+ 'complex64',
+ # ?
+ 'datetime64',
+ 'timedelta64',
+ ]
+
+def create_good_method_func (numpy_data_type):
+ def method(self):
+ "numpy %s" % numpy_data_type
+ import numpy
+ self.result.value = getattr(numpy, numpy_data_type)(pi)
+ return method
+
+def create_bad_method_func (numpy_data_type):
+ def method(self):
+ "numpy %s" % numpy_data_type
+ import numpy
+ try:
+ value = getattr(numpy, numpy_data_type)(pi)
+ except ValueError:
+ value = getattr(numpy, numpy_data_type)()
+ self.assertRaises(TypeError, self.result.__setattr__, 'value', value)
+ return method
+
+for numpy_data_type in good_numpy_data_types:
+ test_method = create_good_method_func (numpy_data_type)
+ test_method.__name__ = 'testOnNumpy_%s' % numpy_data_type
+ test_method.__doc__ = 'groks a numpy %s' % numpy_data_type
+ setattr (TestAnalyzerResult, test_method.__name__, test_method)
+
+for numpy_data_type in bad_numpy_data_types:
+ test_method = create_bad_method_func (numpy_data_type)
+ test_method.__name__ = 'testOnNumpy_%s' % numpy_data_type
+ test_method.__doc__ = 'gasps on numpy %s' % numpy_data_type
+ setattr (TestAnalyzerResult, test_method.__name__, test_method)
+
class TestAnalyzerResultNumpy(TestAnalyzerResult):
""" test AnalyzerResult numpy serialize """