test.py 1.2 KB
Newer Older
S
superjom 已提交
1 2
import sys
import unittest
S
superjom 已提交
3

S
superjom 已提交
4 5 6 7 8
sys.path.append('../../build')
import core

im = core.im()

S
superjom 已提交
9

S
superjom 已提交
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
class StorageTester(unittest.TestCase):
    def setUp(self):
        self.storage = im.storage()

    def test_size(self):
        self.assertEqual(self.storage.tablets_size(), 0)
        im.add_tablet("tag0", 100)
        self.assertEqual(self.storage.tablets_size(), 1)

        for i in range(1, 11):
            im.add_tablet("tag%d" % i, 100)
        self.assertEqual(self.storage.tablets_size(), 11)

    def test_timestamp(self):
        print self.storage.timestamp()

    def test_dir(self):
        dir = "./1.txt"
        self.storage.set_dir(dir)
        self.assertEqual(dir, self.storage.dir())

    def test_human_readable_buffer(self):
        print self.storage.human_readable_buffer()


class TabletTester(unittest.TestCase):
    def setUp(self):
        self.tablet = im.add_tablet("tag101", 20)

    def test_add_scalar(self):
        self.tablet.add_scalar_float(1, 0.3)
        self.assertEqual(self.tablet.records_size(), 1)

    def test_human_readable_buffer(self):
        print self.tablet.human_readable_buffer()


if __name__ == '__main__':
    unittest.main()