Skip to content

Commit

Permalink
[test/{test_axis_range.py,test_util.py}] add test for axis range setting
Browse files Browse the repository at this point in the history
[src/log_plotter/datalogger_plotter_with_pyqtgraph.py] add showMaximize option in main method
  • Loading branch information
rkoyama1623-2021 committed Feb 27, 2017
1 parent b16616c commit 3cfa180
Show file tree
Hide file tree
Showing 5 changed files with 155 additions and 1 deletion.
3 changes: 3 additions & 0 deletions test/config/sample_plot.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
dummy:
data:
- { log: dummy, column: [0] }
11 changes: 11 additions & 0 deletions test/data/sample/sample_data.dummy
Original file line number Diff line number Diff line change
@@ -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
8 changes: 7 additions & 1 deletion test/test_all.py
Original file line number Diff line number Diff line change
@@ -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
99 changes: 99 additions & 0 deletions test/test_axis_range.py
Original file line number Diff line number Diff line change
@@ -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
35 changes: 35 additions & 0 deletions test/test_util.py
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 3cfa180

Please sign in to comment.