From 770ba5201f5c60b2bb36602ff9d359f641e33125 Mon Sep 17 00:00:00 2001 From: Yves Fischer Date: Sun, 23 Oct 2011 21:14:40 +0200 Subject: Charting with flask, rgraph and custom "timeseries database" --- schall/lib/timeseries/tests/testDBSimple.py | 50 +++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 schall/lib/timeseries/tests/testDBSimple.py (limited to 'schall/lib/timeseries/tests/testDBSimple.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] ) -- cgit v1.2.1