test_storage.py 1021 字节
Newer Older
S
superjom 已提交
1
import storage
S
superjom 已提交
2 3
import numpy as np
import unittest
S
superjom 已提交
4
import random
S
superjom 已提交
5
import time
S
superjom 已提交
6

S
superjom 已提交
7
class StorageTest(unittest.TestCase):
S
superjom 已提交
8
    def setUp(self):
S
superjom 已提交
9
        self.dir = "./tmp/storage_test"
S
superjom 已提交
10

S
superjom 已提交
11 12 13
    def test_read(self):
        print 'test write'
        self.writer = storage.StorageWriter(self.dir, sync_cycle=1).as_mode("train")
S
superjom 已提交
14
        scalar = self.writer.scalar("model/scalar/min")
S
superjom 已提交
15
        # scalar.set_caption("model/scalar/min")
S
superjom 已提交
16
        for i in range(10):
S
superjom 已提交
17
            scalar.add_record(i, float(i))
S
superjom 已提交
18

S
superjom 已提交
19
        print 'test read'
S
superjom 已提交
20
        self.reader = storage.StorageReader(self.dir).as_mode("train")
S
superjom 已提交
21
        scalar = self.reader.scalar("model/scalar/min")
S
superjom 已提交
22
        self.assertEqual(scalar.caption(), "train")
S
superjom 已提交
23 24 25 26 27 28
        records = scalar.records()
        ids = scalar.ids()
        self.assertTrue(np.equal(records, [float(i) for i in range(10)]).all())
        self.assertTrue(np.equal(ids, [float(i) for i in range(10)]).all())
        print 'records', records
        print 'ids', ids
S
superjom 已提交
29

S
superjom 已提交
30 31 32

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