-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[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
- Loading branch information
1 parent
b16616c
commit 3cfa180
Showing
5 changed files
with
155 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
dummy: | ||
data: | ||
- { log: dummy, column: [0] } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |