diff options
author | Yves Fischer <yvesf-git@xapek.org> | 2011-10-23 21:14:40 +0200 |
---|---|---|
committer | Yves Fischer <yvesf-git@xapek.org> | 2011-10-30 11:33:54 +0100 |
commit | 770ba5201f5c60b2bb36602ff9d359f641e33125 (patch) | |
tree | 2200757f04efbc281c4b3714bfe2e4fe911193b6 /schall/lib/timeseries/tests | |
parent | 77f5e686612898974e13f2a5df57c20e4e529363 (diff) | |
download | mini-octopus-770ba5201f5c60b2bb36602ff9d359f641e33125.tar.gz mini-octopus-770ba5201f5c60b2bb36602ff9d359f641e33125.zip |
Charting with flask, rgraph and custom "timeseries database"
Diffstat (limited to 'schall/lib/timeseries/tests')
-rw-r--r-- | schall/lib/timeseries/tests/__init__.py | 0 | ||||
-rw-r--r-- | schall/lib/timeseries/tests/testDBSimple.py | 50 |
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] ) |