summaryrefslogtreecommitdiff
path: root/schall/lib/timeseries/tests
diff options
context:
space:
mode:
Diffstat (limited to 'schall/lib/timeseries/tests')
-rw-r--r--schall/lib/timeseries/tests/__init__.py0
-rw-r--r--schall/lib/timeseries/tests/testDBSimple.py50
2 files changed, 50 insertions, 0 deletions
diff --git a/schall/lib/timeseries/tests/__init__.py b/schall/lib/timeseries/tests/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/schall/lib/timeseries/tests/__init__.py
diff --git a/schall/lib/timeseries/tests/testDBSimple.py b/schall/lib/timeseries/tests/testDBSimple.py
new file mode 100644
index 0000000..b1f7630
--- /dev/null
+++ b/schall/lib/timeseries/tests/testDBSimple.py
@@ -0,0 +1,50 @@
+import os
+import random
+import tempfile
+import logging
+import unittest
+
+import timeseries
+
+
+class TestDB(unittest.TestCase):
+ def setUp(self):
+ logging.basicConfig(level=logging.INFO)
+ self.tempdir = tempfile.mkdtemp()
+ self.db = timeseries.DBSimpleInt(timeseries.C.INT_MIN,
+ timeseries.C.INT_DAY,
+ self.tempdir, "t-dbsimple")
+
+ def tearDown(self):
+ self.db.close()
+ for path in os.listdir(self.tempdir):
+ os.remove(os.path.join(self.tempdir, path))
+ os.rmdir(self.tempdir)
+
+class TestEmptyDB(TestDB):
+ def testEmptyDB(self):
+ start=0
+ end=timeseries.C.INT_DAY
+
+ self.assertEqual(self.db[start], 0)
+ self.assertEqual(len(os.listdir(self.tempdir)), 1)
+
+ self.assertEqual(self.db[end-1], 0)
+ self.assertEqual(len(os.listdir(self.tempdir)), 1)
+
+ self.assertEqual(self.db[end], 0)
+ self.assertEqual(len(os.listdir(self.tempdir)), 2)
+
+class TestRandomValues(TestDB):
+ def testRandomValues(self):
+ values={}
+ for i in range(0,100):
+ key = random.randint(0, timeseries.time_ms())
+ value = random.randint(-2147483648, 2147483647)
+ values[key] = value
+ self.db[key] = value
+
+ keys = values.keys()
+ random.shuffle(keys)
+ for key in keys:
+ self.assertEqual( self.db[key], values[key] )