Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

REF larry creation unit tests.

  • Loading branch information...
commit 519fddcf430341e973fc7b1669843e0b0bda2d94 1 parent d37aad3
@kwgoodman authored
View
84 la/tests/deflarry_creation_test.py
@@ -0,0 +1,84 @@
+import os
+import tempfile
+import numpy as np
+import la
+from la import larry
+from la.util.testing import assert_larry_equal as ale
+
+
+def larry_init_list_test():
+ "larry.__init__list"
+ desired = larry([[0, 1], [2, 3]])
+ actual = la.lrange((2, 2))
+ ale(actual, desired, msg='create larry from list')
+
+def larry_init_tuple_test():
+ "larry.__init__tuple"
+ desired = larry(((0, 1), (2, 3)))
+ actual = la.lrange((2, 2))
+ ale(actual, desired, msg='create larry from tuple')
+
+def larry_init_matrix_test():
+ "larry.__init__matrix"
+ desired = larry(np.matrix([[0, 1], [2, 3]]))
+ actual = la.lrange((2, 2))
+ ale(actual, desired, msg='create larry from matrix')
+
+def larry_init_array_test():
+ "larry.__init__array"
+ desired = larry(np.array([[0, 1], [2, 3]]))
+ actual = la.lrange((2, 2))
+ ale(actual, desired, msg='create larry from matrix')
+
+# --------------------------------------------------------------------------
+
+# larry dtype test
+#
+# Make sure the optional dtype input works as expected
+
+def test_dtype():
+ "larry dtype test"
+ dtypes = [float, int, str, bool, complex, object, None]
+ data = [0, 1, 2]
+ msg = 'larry creation failed with dtype %s using a %s as input'
+ for dtype in dtypes:
+ lar1 = larry(list(data), dtype=dtype) # larry does dtype
+ lar2 = larry(np.array(list(data), dtype=dtype)) # array does dtype
+ yield ale, lar1, lar2, msg % (dtype, 'list')
+ lar1 = larry(np.array(list(data)), dtype=dtype) # larry does dtype
+ lar2 = larry(np.array(list(data), dtype=dtype)) # array does dtype
+ yield ale, lar1, lar2, msg % (dtype, 'array')
+
+# --------------------------------------------------------------------------
+
+# Conversion tests
+#
+# The larry conversion methods are:
+#
+# fromtuples, totuples
+# fromlist, tolist
+# fromdict, todict
+#
+# Make sure that larrys don't change after a round trip:
+
+def test_conversion():
+ "Make sure that larrys don't change after a conversion round trip."
+ shapes = [(1,), (1,1), (3,), (3,1), (1,1,1), (1,1,2), (1,2,2), (2,2,2),
+ (3,2,1), (5,4,3,2,1), (0,)]
+ msg = 'Round trip %s conversion failed on shape %s'
+ for shape in shapes:
+ y1 = larry(np.arange(np.prod(shape)).reshape(shape))
+ y2 = larry.fromtuples(y1.copy().totuples())
+ yield ale, y1, y2, msg % ('tuples', str(shape)), False
+ y2 = larry.fromlist(y1.copy().tolist())
+ yield ale, y1, y2, msg % ('list', str(shape)), False
+ y2 = larry.fromdict(y1.copy().todict())
+ yield ale, y1, y2, msg % ('dict', str(shape)), False
+ suffix = '.csv'
+ prefix = 'la_csv_unittest'
+ filename = tempfile.mktemp(suffix=suffix, prefix=prefix)
+ y1.copy().tocsv(filename)
+ y2 = larry.fromcsv(filename)
+ y2 = y2.maplabel(int) # labels loaded as strings; convert to int
+ os.unlink(filename)
+ yield ale, y1, y2, msg % ('csv', str(shape)), False
View
53 la/tests/deflarry_nose_test.py
@@ -2,8 +2,6 @@
# For support of python 2.5
from __future__ import with_statement
-import os
-import tempfile
from copy import deepcopy
from StringIO import StringIO
@@ -479,38 +477,6 @@ def test_binary_regression():
# --------------------------------------------------------------------------
-# Conversion tests
-#
-# The larry conversion methods are:
-#
-# fromtuples, totuples
-# fromlist, tolist
-# fromdict, todict
-#
-# Make sure that larrys don't change after a round trip:
-
-def test_conversion():
- "Make sure that larrys don't change after a conversion round trip."
- shapes = [(1,), (1,1), (3,), (3,1), (1,1,1), (1,1,2), (1,2,2), (2,2,2),
- (3,2,1), (5,4,3,2,1), (0,)]
- msg = 'Round trip %s conversion failed on shape %s'
- for shape in shapes:
- y1 = larry(np.arange(np.prod(shape)).reshape(shape))
- y2 = larry.fromtuples(y1.copy().totuples())
- yield ale, y1, y2, msg % ('tuples', str(shape)), False
- y2 = larry.fromlist(y1.copy().tolist())
- yield ale, y1, y2, msg % ('list', str(shape)), False
- y2 = larry.fromdict(y1.copy().todict())
- yield ale, y1, y2, msg % ('dict', str(shape)), False
- suffix = '.csv'
- prefix = 'la_csv_unittest'
- filename = tempfile.mktemp(suffix=suffix, prefix=prefix)
- y1.copy().tocsv(filename)
- y2 = larry.fromcsv(filename)
- y2 = y2.maplabel(int) # labels loaded as strings; convert to int
- os.unlink(filename)
- yield ale, y1, y2, msg % ('csv', str(shape)), False
-
# tofile does not yet have a from file, so it cannot be tested with the
# roundtrip method above. (Besides it only supports 1d and 2d larrys).
# Test separately:
@@ -536,25 +502,6 @@ def test_tofile():
# --------------------------------------------------------------------------
-# larry dtype test
-#
-# Make sure the optional dtype input works as expected
-
-def test_dtype():
- "larry dtype test"
- dtypes = [float, int, str, bool, complex, object, None]
- data = [0, 1, 2]
- msg = 'larry creation failed with dtype %s using a %s as input'
- for dtype in dtypes:
- lar1 = larry(list(data), dtype=dtype) # larry does dtype
- lar2 = larry(np.array(list(data), dtype=dtype)) # array does dtype
- yield ale, lar1, lar2, msg % (dtype, 'list')
- lar1 = larry(np.array(list(data)), dtype=dtype) # larry does dtype
- lar2 = larry(np.array(list(data), dtype=dtype)) # array does dtype
- yield ale, lar1, lar2, msg % (dtype, 'array')
-
-# --------------------------------------------------------------------------
-
# larry astype test
#
# Make sure the astype input works as expected
View
31 la/tests/deflarry_test.py
@@ -17,37 +17,6 @@
from la.util.testing import assert_larry_equal as ale
-class Test_init(unittest.TestCase):
- "Test init of larry class"
-
- def setUp(self):
- self.list = [[1,2],[3,4]]
- self.tuple = ((1,2),(3,4))
- self.matrix = np.matrix([[1,2],[3,4]])
- self.array = np.array([[1,2],[3,4]])
- self.label = [[0,1],[0,1]]
- self.desired = la.lrange((2,2)) + 1
-
- def test_init_list(self):
- "larry.__init__list"
- actual = larry(self.list)
- ale(actual, self.desired, msg='create larry from list')
-
- def test_init_tuple(self):
- "larry.__init__tuple"
- actual = larry(self.tuple)
- ale(actual, self.desired, msg='create larry from tuple')
-
- def test_init_matrix(self):
- "larry.__init__matrix"
- actual = larry(self.matrix)
- ale(actual, self.desired, msg='create larry from matrix')
-
- def test_init_array(self):
- "larry.__init__array"
- actual = larry(self.array)
- ale(actual, self.desired, msg='create larry from array')
-
class Test_binary(unittest.TestCase):
"Test binary functions of Data class"
Please sign in to comment.
Something went wrong with that request. Please try again.