From 3cfa18039e55d16d2999793860e30e785019fa16 Mon Sep 17 00:00:00 2001 From: Ryo KOYAMA Date: Sat, 25 Feb 2017 11:29:23 +0900 Subject: [PATCH] [test/{test_axis_range.py,test_util.py}] add test for axis range setting [src/log_plotter/datalogger_plotter_with_pyqtgraph.py] add showMaximize option in main method --- test/config/sample_plot.yaml | 3 + test/data/sample/sample_data.dummy | 11 ++++ test/test_all.py | 8 ++- test/test_axis_range.py | 99 ++++++++++++++++++++++++++++++ test/test_util.py | 35 +++++++++++ 5 files changed, 155 insertions(+), 1 deletion(-) create mode 100644 test/config/sample_plot.yaml create mode 100644 test/data/sample/sample_data.dummy create mode 100755 test/test_axis_range.py create mode 100644 test/test_util.py diff --git a/test/config/sample_plot.yaml b/test/config/sample_plot.yaml new file mode 100644 index 0000000..5537c0f --- /dev/null +++ b/test/config/sample_plot.yaml @@ -0,0 +1,3 @@ +dummy: + data: + - { log: dummy, column: [0] } diff --git a/test/data/sample/sample_data.dummy b/test/data/sample/sample_data.dummy new file mode 100644 index 0000000..1d5b419 --- /dev/null +++ b/test/data/sample/sample_data.dummy @@ -0,0 +1,11 @@ +0 3 +1 4 +2 5 +3 6 +4 7 +5 8 +6 9 +7 10 +8 11 +9 12 +10 13 \ No newline at end of file diff --git a/test/test_all.py b/test/test_all.py index 791d2ab..9b54ba7 100755 --- a/test/test_all.py +++ b/test/test_all.py @@ -1,7 +1,13 @@ #!/usr/bin/python #-*- coding:utf-8 -*- import unittest +import pyqtgraph from test_log_parser import * +from test_axis_range import * if __name__ == '__main__': - unittest.main(verbosity=2) + app = pyqtgraph.Qt.QtGui.QApplication([]) + try: + unittest.main(verbosity=2) + finally: + del app diff --git a/test/test_axis_range.py b/test/test_axis_range.py new file mode 100755 index 0000000..dea6bf7 --- /dev/null +++ b/test/test_axis_range.py @@ -0,0 +1,99 @@ +#!/usr/bin/python +#-*- coding:utf-8 -*- + +import pyqtgraph +from numpy import isclose +import unittest.main +from unittest import TestCase +from test_util import log_plotter_exec + +class TestLogPlotter(TestCase): + def test_x_range(self): + layout =u''' +main: + graph of dummy: + legends: + - { key: dummy, id: [0] } + yRange: {min: 7, max: 10} + +''' + a = log_plotter_exec(layout=layout, + plot_conf ='config/sample_plot.yaml', + fname = 'data/sample/sample_data', + eventLoop=10) + # check xRange + ax = a.view.ci.rows[0][0].getAxis('bottom') + range_min = ax.range[0] + range_max = ax.range[1] + self.assertTrue(isclose(range_min, 0, atol=1), msg='bottom axis min is not correct. range_min={}'.format(range_min)) + self.assertTrue(isclose(range_max, 10,atol=1), msg='bottom axis max is not correct. range_max={}'.format(range_max)) + + # check yRange + ax = a.view.ci.rows[0][0].getAxis('left') + range_min = ax.range[0] + range_max = ax.range[1] + self.assertTrue(isclose(range_min, 7, atol=1), msg='left axis min is not correct. range_min={}'.format(range_min)) + self.assertTrue(isclose(range_max, 10, atol=1), msg='left axis max is not correct. range_max={}'.format(range_max)) + + def test_x_range2(self): + layout =u''' +main: + graph of dummy: + legends: + - { key: dummy, id: [0] } + xRange: {min: 3, max: 10} +''' + + a = log_plotter_exec(layout=layout, + plot_conf ='config/sample_plot.yaml', + fname = 'data/sample/sample_data', + eventLoop=10) + # check xRange + ax = a.view.ci.rows[0][0].getAxis('bottom') + range_min = ax.range[0] + range_max = ax.range[1] + self.assertTrue(isclose(range_min, 3, atol=1), msg='left axis min is not correct. range_min={}'.format(range_min)) + self.assertTrue(isclose(range_max, 10, atol=1), msg='left axis max is not correct. range_max={}'.format(range_max)) + + # check yRange + ax = a.view.ci.rows[0][0].getAxis('left') + range_min = ax.range[0] + range_max = ax.range[1] + self.assertTrue(isclose(range_min, 3, atol=1), msg='left axis min is not correct. range_min={}'.format(range_min)) + self.assertTrue(isclose(range_max, 13, atol=1), msg='left axis max is not correct. range_max={}'.format(range_max)) + + + def test_x_range3(self): + layout =u''' +main: + graph of dummy: + legends: + - { key: dummy, id: [0] } + xRange: {min: 3, max: 10, zero: True} +''' + a = log_plotter_exec(layout=layout, + plot_conf ='config/sample_plot.yaml', + fname = 'data/sample/sample_data', + eventLoop=10) + # check xRange + ax = a.view.ci.rows[0][0].getAxis('bottom') + range_min = ax.range[0] + range_max = ax.range[1] + self.assertTrue(isclose(range_min, 0, atol=1), msg='left axis min is not correct. range_min={}'.format(range_min)) + self.assertTrue(isclose(range_max, 7, atol=1), msg='left axis max is not correct. range_max={}'.format(range_max)) + + # check yRange + ax = a.view.ci.rows[0][0].getAxis('left') + range_min = ax.range[0] + range_max = ax.range[1] + self.assertTrue(isclose(range_min, 3, atol=1), msg='left axis min is not correct. range_min={}'.format(range_min)) + self.assertTrue(isclose(range_max, 13, atol=1), msg='left axis max is not correct. range_max={}'.format(range_max)) + +__all__ = ['TestLogPlotter'] + +if __name__ == '__main__': + app = pyqtgraph.Qt.QtGui.QApplication([]) + try: + unittest.main(verbosity=2) + finally: + del app diff --git a/test/test_util.py b/test/test_util.py new file mode 100644 index 0000000..e192f81 --- /dev/null +++ b/test/test_util.py @@ -0,0 +1,35 @@ +import pyqtgraph +from log_plotter.datalogger_plotter_with_pyqtgraph import LogPlotter + +def log_plotter_exec(layout = None, plot = None, + layout_conf = None, plot_conf = None, + fname = None, title = 'test log_lotter', + run=True, eventLoop=0): + ''' + generate and run log_plotter from str or conf file. + layout or layout_conf is necessary. + plot or plot_conf is necessary. + + :param str layout: contents of layout.yaml + :param str plot: contents of plot.yaml + :param str layout_conf: path to layout.yaml + :param str plot_conf: path to plot.yaml + :param str fname: path to log file + :param str title: graph window title + :param bool run: if True, run LogPlotter.main() + ''' + if layout is not None and layout_conf is None: + layout_conf = '/tmp/tmp_layout.yaml' + with open(layout_conf, 'w') as f: + f.write(layout) + if plot is not None and plot_conf is None: + plot_conf = '/tmp/tmp_plot.yaml' + with open(layout_conf, 'w') as f: + f.write(layout) + # import pdb;pdb.set_trace() + a = LogPlotter(fname, plot_conf, layout_conf) + if run: + a.main() + app = pyqtgraph.QtCore.QCoreApplication.instance() + [app.processEvents() for i in range(eventLoop)] + return a