Permalink
Browse files

TST better unit test coverage of IO class

  • Loading branch information...
1 parent 5c18810 commit 907c74ea6d7cd1f64f245a14009758e66caf1d42 @kwgoodman committed Jan 8, 2014
Showing with 90 additions and 3 deletions.
  1. +2 −2 README.rst
  2. +4 −1 la/io.py
  3. +84 −0 la/tests/io_test.py
View
4 README.rst
@@ -120,9 +120,9 @@ After you have installed ``la``, run the suite of unit tests::
>>> import la
>>> la.test()
<snip>
- Ran 2996 tests in 9.225s
+ Ran 3003 tests in 12.225s
OK
- <nose.result.TextTestResult run=2996 errors=0 failures=0>
+ <nose.result.TextTestResult run=3003 errors=0 failures=0>
The ``la`` package contains C extensions that speed up common alignment
operations such as adding two unaligned larrys. If the C extensions don't
View
5 la/io.py
@@ -170,7 +170,10 @@ def merge(self, key, lar, update=False):
lar2 = lar1.merge(lar, update=update)
del self.f[key]
self[key] = lar2
-
+
+ def __iter__(self):
+ return iter(self.keys())
+
def __len__(self):
return len(self.keys())
View
84 la/tests/io_test.py
@@ -108,6 +108,90 @@ def test_io_7(self):
actual = la.larry([])
assert_larry_equal(actual, desired)
+ def test_io_values(self):
+ "io_values"
+ io = IO(self.filename)
+ x = larry([1,2,3])
+ y = larry([7,8,9])
+ io['x'] = x
+ io['y'] = y
+ values = io.values()
+ values = [v[:] for v in values]
+ assert_larry_equal(values[0], x)
+ assert_larry_equal(values[1], y)
+
+ def test_io_items(self):
+ "io_items"
+ io = IO(self.filename)
+ x = larry([1,2,3])
+ y = larry([7,8,9])
+ io['x'] = x
+ io['y'] = y
+ items = io.items()
+ values = [v[1][:] for v in items]
+ assert_larry_equal(values[0], x)
+ assert_larry_equal(values[1], y)
+ keys = [v[0] for v in items]
+ self.assertTrue(keys == ['x', 'y'], 'keys do not match')
+
+ def test_io_iterkeys(self):
+ "io_iterkeys"
+ io = IO(self.filename)
+ x = larry([1,2,3])
+ y = larry([7,8,9])
+ io['x'] = x
+ io['y'] = y
+ itk = io.iterkeys()
+ keys = [k for k in itk]
+ self.assertTrue(keys == ['x', 'y'], 'keys do not match')
+
+ def test_io_itervalues(self):
+ "io_itervalues"
+ io = IO(self.filename)
+ x = larry([1,2,3])
+ y = larry([7,8,9])
+ io['x'] = x
+ io['y'] = y
+ itv = io.itervalues()
+ values = [v[:] for v in itv]
+ assert_larry_equal(values[0], x)
+ assert_larry_equal(values[1], y)
+
+ def test_io_iteritems(self):
+ "io_iteritems"
+ io = IO(self.filename)
+ x = larry([1,2,3])
+ y = larry([7,8,9])
+ io['x'] = x
+ io['y'] = y
+ iti = io.iteritems()
+ items = [i for i in iti]
+ values = [v[1][:] for v in items]
+ assert_larry_equal(values[0], x)
+ assert_larry_equal(values[1], y)
+ keys = [v[0] for v in items]
+ self.assertTrue(keys == ['x', 'y'], 'keys do not match')
+
+ def test_io_haskey(self):
+ "io_haskey"
+ io = IO(self.filename)
+ x = larry([1,2,3])
+ y = larry([7,8,9])
+ io['x'] = x
+ io['y'] = y
+ self.assertTrue(io.has_key('x'), 'keys do not match')
+ self.assertTrue(io.has_key('y'), 'keys do not match')
+ self.assertTrue(~io.has_key('z'), 'keys do not match')
+
+ def test_io_len(self):
+ "io_len"
+ io = IO(self.filename)
+ x = larry([1,2,3])
+ y = larry([7,8,9])
+ io['x'] = x
+ io['y'] = y
+ self.assertTrue(len(io) == 2, 'number of keys is wrong')
+
# nose tests ----------------------------------------------------------------
def datetime_test():

0 comments on commit 907c74e

Please sign in to comment.