From dd626d65f4b6732c1f1e2ac435baa590b5ced78e Mon Sep 17 00:00:00 2001 From: superjom Date: Mon, 20 Nov 2017 16:53:42 +0800 Subject: [PATCH] add more python test --- visualdl/backend/logic/pybind.cc | 1 + visualdl/backend/logic/test.py | 11 -------- visualdl/backend/test.py | 46 ++++++++++++++++++++++++++++++++ 3 files changed, 47 insertions(+), 11 deletions(-) delete mode 100644 visualdl/backend/logic/test.py create mode 100644 visualdl/backend/test.py diff --git a/visualdl/backend/logic/pybind.cc b/visualdl/backend/logic/pybind.cc index c977963e..242c25d3 100644 --- a/visualdl/backend/logic/pybind.cc +++ b/visualdl/backend/logic/pybind.cc @@ -35,6 +35,7 @@ PYBIND11_MODULE(core, m) { py::class_(m, "Storage") .def("timestamp", &vs::StorageHelper::timestamp) .def("dir", &vs::StorageHelper::dir) + .def("set_dir", &vs::StorageHelper::SetDir) .def("tablets_size", &vs::StorageHelper::tablets_size) .def("buffer", &vs::StorageHelper::buffer) .def("human_readable_buffer", &vs::StorageHelper::human_readable_buffer) diff --git a/visualdl/backend/logic/test.py b/visualdl/backend/logic/test.py deleted file mode 100644 index 36040898..00000000 --- a/visualdl/backend/logic/test.py +++ /dev/null @@ -1,11 +0,0 @@ -import core - -im = core.im() - -im.add_tablet("tag0", 50) - -tablet = im.tablet("tag0") -tablet.add_scalar_int32(1, 13) - -print "buffer", tablet.buffer() -print "buffer", tablet.human_readable_buffer() diff --git a/visualdl/backend/test.py b/visualdl/backend/test.py new file mode 100644 index 00000000..f0cd54d6 --- /dev/null +++ b/visualdl/backend/test.py @@ -0,0 +1,46 @@ +import sys +import unittest +sys.path.append('../../build') +import core + +im = core.im() + +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() -- GitLab