Commits

Stefan Scherfke committed c490089

Tests for PyTables storage

Comments (0)

Files changed (3)

collectors/storage/pytables.py

 
 
 class PyTables(BaseStorage):
-    def __init__(self, hd5file, group, dtypes):
-        self.hd5file = hd5file
+    def __init__(self, h5file, group, dtypes):
+        self.h5file = h5file
         self.group = group \
                 if isinstance(group, tables.Group) \
-                else self.hd5file.createGroup('/', group)
+                else self.h5file.createGroup('/', group)
         self.dtypes = dtypes
 
         self.append = lambda series, value: series.append([value])
 
     def create_series(self, name, index):
-        return self.hd5file.createEArray(self.group, name,
+        return self.h5file.createEArray(self.group, name,
                 tables.Atom.from_kind(self.dtypes[index]), (0,))

collectors/test/test_storage_excel.py

 
 from unittest import TestCase
 
-from collectors.storages.excel import Excel, ExcelSeries
+from collectors.storage.excel import Excel, ExcelSeries
 
 
 class ExcelSeriesTest(TestCase):

collectors/test/test_storage_pytables.py

 # encoding: utf-8
 
 from unittest import TestCase
+import tempfile
 
 import tables
 
 
 
 class PyTablesTest(TestCase):
-    pass
+
+    def setUp(self):
+        tmpfile = tempfile.NamedTemporaryFile(mode='r')
+        h5file = tables.openFile(tmpfile.name, mode='w')
+
+        self.pt = PyTables(h5file, 'foo', ('int', 'float'))
+
+    def tearDown(self):
+        self.pt.h5file.close()
+
+    def test_init(self):
+        assert self.pt.dtypes == ('int', 'float')
+        assert self.pt.h5file.getNode('/', 'foo')
+
+    def test_create_series(self):
+        series = self.pt.create_series('bar', 0)
+        assert series == self.pt.h5file.getNode('/foo', 'bar')
+
+    def test_append(self):
+        series = self.pt.create_series('bar', 0)
+        self.pt.append(series, 23)
+        assert series[0] == 23