1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
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] )
|