Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add unittest #94

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/log_plotter/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from log_parser import LogParser
from datalogger_plotter_with_pyqtgraph import *
try:
from version import version as __version__
Expand Down
2 changes: 1 addition & 1 deletion src/log_plotter/datalogger_plotter_with_pyqtgraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@


class LogPlotter(object):
def __init__(self, fname, plot_conf_name, layout_conf_name, title):
def __init__(self, fname, plot_conf_name, layout_conf_name, title=None):
'''
:param str fname: file name of log
:param str plot_conf_name: plot yaml file name
Expand Down
1 change: 1 addition & 0 deletions test/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__pycache__/*
50 changes: 50 additions & 0 deletions test/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# test
## テストの走らせ方
### 仮想ディスプレイのインストールと立ち上げ
```bash
sudo apt-get install xvfb
/sbin/start-stop-daemon --start --quiet --pidfile /tmp/custom_xvfb_99.pid --make-pidfile --background --exec /usr/bin/Xvfb -- :99 -screen 0 1400x900x24 -ac +extension GLX +render # copy from pyqtgraph .travis.yaml
export DISPLAY=:99.0
```

### テストの実行
1. 全部をテスト
```bash
python test_all.py
```
2. 個別にテスト
```bash
python test_xxx.py
```

## テストのTips
- unittestのパッケージを使用.
- pytestは,catkinとの相性が良くない模様.(devel以下の`__init__.py`の読み込みでエラーが出る)
- テストを作るには,unittest.TestCaseを継承したクラスに,test_xxxという名称のメソッドを定義して作る,
- テストを走らせるには,`unittest.main()`を実行すると,`test_xxx`メソッドを順に実行してくれる.
- assertionは,unittest.TestCaseのメソッドである,assertXXXを利用するとテストが失敗したときに見やすく表示される.

```python
import unittest

class TestXXX(unittest.TestCase):
def test_hogehoge(self):
# write test here
x = 1
self.assertEqual(x,1,'x is {}. not 1'.format(x))

if __name__ == '__main__':
unittest.main()
```
- `unittest.main`はテストが終わると,そのまま`exit`しようとするが,ガーベジコレクションの順番によって時々Segmentation Faultが発生する.
以下のようにテスト終了後に`QtGui.QApplication`の消去を明示的に行うとエラーが消えた.
```python
if __name__ == '__main__':
app = pyqtgraph.Qt.QtGui.QApplication([])
try:
unittest.main()
finally:
del app
```


43 changes: 43 additions & 0 deletions test/check_graph_appearance.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/usr/bin/python
#-*- coding:utf-8 -*-

import argparse
import signal
import pyqtgraph
from test_util import log_plotter_exec


def show_graph():
layout =u'''
main:
graph of dummy:
legends:
- { key: dummy, id: [0] }
- { key: dummy, id: [0] }
'''
a = log_plotter_exec(layout=layout,
plot_conf ='config/sample_plot.yaml',
fname = 'data/sample/sample_data')
a.view.showMaximized()
return a

if __name__ == '__main__':
parser = argparse.ArgumentParser(description='plot data from hrpsys log')
parser.add_argument("-i", action='store_true', help='interactive (start IPython)')
parser.set_defaults(feature=False)
args = parser.parse_args()

app = pyqtgraph.Qt.QtGui.QApplication([])
a = show_graph()
if args.i:
[app.processEvents() for i in range(2)]
# start ipython
print '====='
print "please use \033[33mapp.processEvents()\033[m to update graph."
print "you can use \033[33ma\033[m as LogPlotter instance."
print '====='
from IPython import embed
embed()
else:
signal.signal(signal.SIGINT, signal.SIG_DFL)
pyqtgraph.Qt.QtGui.QApplication.instance().exec_()
4 changes: 4 additions & 0 deletions test/config/jaxon_joint_layout.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
main:
rleg_joint_angle:
legends:
- { key: st_q, id: [0-5] }
4 changes: 4 additions & 0 deletions test/config/jaxon_watt_layout.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
main:
watt:
legends:
- { key: watt, id: [0-5] }
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] }
10 changes: 10 additions & 0 deletions test/data/jaxon_test_data/jaxon_test.RobotHardware0_dq
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
1450271115.915908 0.092039 -0.057674 0.000000 -0.035953 0.048936 0.011910 0.210922 -0.062168 0.015579 -0.093477 -0.025966 0.045257 0.009737 -0.031459 -0.050184 0.000000 -0.000000 0.006866 -0.013108 -0.013108 -0.000000 -0.019350 -0.000000 0.000000 0.000000 -0.021846 -0.019350 -0.000000 -0.000000 -0.007490 -0.000000 0.000000 -0.000000
1450271115.917910 0.080534 -0.060670 0.000000 -0.038350 0.051932 0.000000 0.207087 -0.060670 0.011984 -0.091080 -0.025966 0.046448 0.011984 -0.031459 -0.056925 0.000000 -0.000000 0.008114 -0.013732 -0.012484 -0.004369 -0.019974 -0.000000 0.000000 0.000000 -0.020598 -0.019974 0.008114 -0.000000 -0.006866 -0.000000 0.000000 -0.000000
1450271115.919906 0.095874 -0.058423 0.000000 -0.039548 0.051932 0.000000 0.201335 -0.056176 0.010786 -0.093477 -0.026965 0.045257 0.008239 -0.030710 -0.053929 0.000000 -0.000000 0.002497 -0.013732 -0.013732 -0.006242 -0.019350 -0.000000 0.000000 0.000000 -0.021222 -0.019974 -0.000000 -0.000000 -0.006866 -0.000000 0.000000 -0.000000
1450271115.921905 0.088204 -0.055427 0.000000 -0.043143 0.048936 0.000000 0.203252 -0.059921 -0.000000 -0.094675 -0.021971 0.051212 0.012733 -0.030710 -0.055427 0.000000 -0.000000 -0.000000 -0.014356 -0.014980 -0.004369 -0.019350 -0.000000 0.000000 0.000000 -0.019974 -0.019974 -0.000000 -0.000000 -0.006866 -0.000000 0.000000 -0.000000
1450271115.923906 0.090121 -0.048686 0.001198 -0.039548 0.049934 0.000000 0.199418 -0.061419 -0.000000 -0.083890 -0.022970 0.044066 0.013482 -0.027714 -0.052431 0.000000 -0.000000 0.000624 -0.014356 -0.014980 -0.000624 -0.019974 -0.000000 0.000000 0.000000 -0.019974 -0.019350 0.003745 -0.000000 -0.005618 -0.000000 0.000000 -0.000000
1450271115.925901 0.092039 -0.058423 0.000000 -0.043143 0.050933 0.000000 0.199418 -0.061419 -0.000000 -0.089882 -0.024967 0.045257 0.015729 -0.030710 -0.049435 0.000000 -0.000000 0.003745 -0.016853 -0.014356 -0.000000 -0.019350 -0.000000 0.000000 0.000000 -0.021846 -0.019974 0.006242 -0.000000 -0.006866 -0.000000 0.000000 -0.000000
1450271115.927914 0.103544 -0.059172 0.000000 -0.044342 0.050933 0.000000 0.182160 -0.060670 -0.000000 -0.095874 -0.023968 0.042875 0.012733 -0.028463 -0.047188 0.000000 -0.000000 0.006242 -0.014980 -0.014980 -0.000000 -0.019974 -0.000000 0.000000 0.000000 -0.021846 -0.019350 -0.000000 -0.000000 -0.007490 -0.000000 0.000000 -0.000000
1450271115.929904 0.101626 -0.066662 0.000000 -0.044342 0.049934 0.000000 0.195583 -0.056925 -0.015579 -0.098271 -0.022970 0.039302 0.012733 -0.029961 -0.049435 0.000000 -0.000000 0.006866 -0.014980 -0.013732 -0.000624 -0.019974 -0.000000 0.000000 0.000000 -0.022470 -0.018725 -0.000000 0.006866 -0.007490 -0.000000 0.000000 -0.000000
1450271115.931911 0.092039 -0.060670 0.000000 -0.047937 0.047937 0.000000 0.182160 -0.062917 -0.000000 -0.099469 -0.024967 0.041684 0.014980 -0.029212 -0.048686 0.000000 -0.000000 0.006866 -0.015604 -0.013732 -0.000624 -0.021222 -0.000000 0.000000 0.000000 -0.021222 -0.019350 0.000624 -0.000000 -0.006866 -0.000000 0.000000 -0.000000
1450271115.933913 0.099709 -0.060670 0.000000 -0.043143 0.048936 0.000000 0.191748 -0.062168 -0.000000 -0.095874 -0.023968 0.033347 0.014980 -0.030710 -0.045690 0.000000 -0.000000 0.006866 -0.015604 -0.014356 -0.003121 -0.020598 -0.000000 0.000000 0.000000 -0.019350 -0.016229 0.006242 -0.000000 -0.008114 -0.000000 0.000000 -0.000000
10 changes: 10 additions & 0 deletions test/data/jaxon_test_data/jaxon_test.RobotHardware0_gsensor
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
1450271115.915908 4.077332 2.585722 8.340581
1450271115.917910 4.035259 2.488658 8.395165
1450271115.919906 3.956340 2.488382 8.407433
1450271115.921905 3.944389 2.512499 8.412364
1450271115.923906 3.896712 2.543768 8.417485
1450271115.925901 3.851981 2.604631 8.298735
1450271115.927914 3.814988 2.563691 8.243866
1450271115.929904 3.902089 2.696583 8.308473
1450271115.931911 3.908638 2.618691 8.427313
1450271115.933913 3.867530 2.603962 8.451271
10 changes: 10 additions & 0 deletions test/data/jaxon_test_data/jaxon_test.RobotHardware0_gyrometer
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
1450271115.915908 -0.117920 0.146694 -0.106727
1450271115.917910 -0.110863 0.135203 -0.112875
1450271115.919906 -0.108012 0.144739 -0.114801
1450271115.921905 -0.108954 0.138060 -0.114453
1450271115.923906 -0.106139 0.144998 -0.125136
1450271115.925901 -0.110663 0.143359 -0.133624
1450271115.927914 -0.129605 0.144000 -0.135637
1450271115.929904 -0.128039 0.145551 -0.142216
1450271115.931911 -0.126148 0.147437 -0.146597
1450271115.933913 -0.128761 0.148667 -0.154773
10 changes: 10 additions & 0 deletions test/data/jaxon_test_data/jaxon_test.RobotHardware0_lfsensor
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
1450271115.915908 -35.599998 56.700001 -182.199997 16.500000 14.730000 6.360000
1450271115.917910 -34.900002 55.700001 -181.199997 16.469999 14.370000 6.300000
1450271115.919906 -33.900002 56.599998 -180.600006 16.469999 14.160000 6.330000
1450271115.921905 -33.599998 56.000000 -180.600006 16.410000 13.800000 6.270000
1450271115.923906 -31.400000 57.200001 -179.000000 16.320000 13.440000 6.360000
1450271115.925901 -29.400000 57.000000 -179.399994 16.290001 13.110000 6.390000
1450271115.927914 -27.799999 56.500000 -179.000000 16.290001 12.870000 6.210000
1450271115.929904 -26.600000 59.000000 -180.000000 16.350000 12.570000 6.180000
1450271115.931911 -24.500000 58.099998 -179.199997 16.320000 12.300000 6.210000
1450271115.933913 -22.900000 58.599998 -178.199997 16.260000 11.940000 6.180000
10 changes: 10 additions & 0 deletions test/data/jaxon_test_data/jaxon_test.RobotHardware0_lhsensor
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
1450271115.915908 4.064941 5.749512 -15.966797 -0.561523 -0.009766 -0.058594
1450271115.917910 3.515625 5.493164 -16.113281 -0.485840 -0.061035 -0.048828
1450271115.919906 3.332520 5.383301 -15.673828 -0.456543 -0.090332 -0.039062
1450271115.921905 3.332520 5.273438 -16.040039 -0.454102 -0.080566 -0.036621
1450271115.923906 3.442383 5.493164 -15.893555 -0.490723 -0.056152 -0.058594
1450271115.925901 4.101562 5.749512 -15.454102 -0.549316 0.000000 -0.065918
1450271115.927914 4.284668 5.712891 -15.747070 -0.561523 0.036621 -0.063477
1450271115.929904 4.284668 5.639648 -15.234375 -0.546875 0.026855 -0.068359
1450271115.931911 4.284668 5.090332 -15.673828 -0.498047 0.007324 -0.046387
1450271115.933913 3.881836 4.797363 -15.820312 -0.427246 -0.026855 -0.046387
10 changes: 10 additions & 0 deletions test/data/jaxon_test_data/jaxon_test.RobotHardware0_q
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
1450271115.915908 -0.194988 0.270962 -0.449666 1.895637 -0.848230 -0.226039 -0.313112 0.414036 -0.308295 1.308578 -0.662352 -0.196483 -0.154462 -0.021729 0.125402 -0.002182 0.002182 -0.010036 0.720057 -0.340012 -0.083885 -1.331686 0.002073 0.001745 -0.345922 0.041124 0.725293 0.289943 0.065668 -1.374338 -0.000545 -0.006654 -0.347548
1450271115.917910 -0.194988 0.271093 -0.449666 1.895637 -0.848404 -0.226039 -0.313322 0.414167 -0.308295 1.308787 -0.662178 -0.196483 -0.154593 -0.021729 0.125402 -0.002182 0.002182 -0.010036 0.720057 -0.339903 -0.083885 -1.331686 0.002073 0.001745 -0.345922 0.041124 0.725402 0.289943 0.065668 -1.374338 -0.000545 -0.006654 -0.347548
1450271115.919906 -0.195198 0.271224 -0.449666 1.895846 -0.848404 -0.226039 -0.313531 0.414167 -0.308295 1.308997 -0.662178 -0.196483 -0.154593 -0.021598 0.125533 -0.002182 0.002182 -0.010036 0.720057 -0.339903 -0.083885 -1.331686 0.002073 0.001745 -0.345922 0.041124 0.725402 0.289943 0.065668 -1.374338 -0.000545 -0.006654 -0.347548
1450271115.921905 -0.195198 0.271355 -0.449666 1.895846 -0.848579 -0.226039 -0.313740 0.414298 -0.308295 1.309206 -0.662178 -0.196691 -0.154593 -0.021598 0.125664 -0.002182 0.002182 -0.010036 0.720166 -0.339903 -0.083885 -1.331577 0.002073 0.001745 -0.345922 0.041233 0.725402 0.289943 0.065668 -1.374229 -0.000545 -0.006654 -0.347548
1450271115.923906 -0.195407 0.271486 -0.449666 1.895846 -0.848579 -0.226039 -0.313950 0.414428 -0.308295 1.309416 -0.662178 -0.196691 -0.154593 -0.021468 0.125795 -0.002182 0.002182 -0.010145 0.720166 -0.339903 -0.083885 -1.331577 0.002073 0.001745 -0.345922 0.041233 0.725511 0.289834 0.065668 -1.374229 -0.000545 -0.006654 -0.347548
1450271115.925901 -0.195407 0.271486 -0.449666 1.896056 -0.848753 -0.226039 -0.314369 0.414559 -0.308295 1.309625 -0.662003 -0.196899 -0.154593 -0.021468 0.125925 -0.002182 0.002182 -0.010145 0.720166 -0.339794 -0.083885 -1.331468 0.002073 0.001745 -0.345922 0.041233 0.725511 0.289834 0.065668 -1.374229 -0.000545 -0.006654 -0.347548
1450271115.927914 -0.195616 0.271617 -0.449666 1.896056 -0.848928 -0.226039 -0.314578 0.414690 -0.308295 1.309834 -0.662003 -0.196899 -0.154593 -0.021337 0.125925 -0.002182 0.002182 -0.010145 0.720166 -0.339794 -0.083885 -1.331468 0.002073 0.001745 -0.345922 0.041342 0.725511 0.289834 0.065668 -1.374229 -0.000545 -0.006654 -0.347548
1450271115.929904 -0.195826 0.271748 -0.449666 1.896265 -0.848928 -0.226039 -0.314788 0.414821 -0.308295 1.310044 -0.662003 -0.197107 -0.154723 -0.021337 0.126056 -0.002182 0.002182 -0.010145 0.720276 -0.339794 -0.083885 -1.331468 0.002073 0.001745 -0.345922 0.041342 0.725621 0.289834 0.065668 -1.374229 -0.000545 -0.006654 -0.347548
1450271115.931911 -0.195826 0.271879 -0.449666 1.896265 -0.849102 -0.226039 -0.314997 0.414952 -0.308295 1.310253 -0.661829 -0.197107 -0.154723 -0.021206 0.126187 -0.002182 0.002182 -0.010145 0.720276 -0.339794 -0.083885 -1.331359 0.002073 0.001745 -0.345922 0.041452 0.725621 0.289834 0.065668 -1.374229 -0.000545 -0.006654 -0.347548
1450271115.933913 -0.196035 0.272010 -0.449876 1.896474 -0.849102 -0.226039 -0.315206 0.415083 -0.308295 1.310253 -0.661829 -0.197107 -0.154723 -0.021206 0.126318 -0.002182 0.002182 -0.010145 0.720276 -0.339685 -0.083885 -1.331359 0.002073 0.001745 -0.345922 0.041452 0.725730 0.289834 0.065668 -1.374229 -0.000545 -0.006654 -0.347548
10 changes: 10 additions & 0 deletions test/data/jaxon_test_data/jaxon_test.RobotHardware0_rfsensor
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
1450271115.915908 -46.599998 38.599998 -106.599998 8.010000 -15.720000 1.200000
1450271115.917910 -47.000000 38.200001 -107.599998 8.100000 -15.900000 1.200000
1450271115.919906 -46.900002 38.599998 -108.599998 8.160000 -16.080000 1.170000
1450271115.921905 -46.299999 38.900002 -110.199997 8.280000 -16.230000 1.200000
1450271115.923906 -46.599998 39.400002 -112.000000 8.370000 -16.350000 1.170000
1450271115.925901 -46.099998 39.200001 -113.400002 8.460000 -16.530001 1.200000
1450271115.927914 -45.900002 40.400002 -114.599998 8.550000 -16.709999 1.170000
1450271115.929904 -46.599998 39.900002 -115.199997 8.610000 -16.830000 1.080000
1450271115.931911 -47.500000 41.500000 -117.199997 8.730000 -17.070000 1.020000
1450271115.933913 -46.400002 40.700001 -118.599998 8.820000 -17.250000 0.930000
10 changes: 10 additions & 0 deletions test/data/jaxon_test_data/jaxon_test.RobotHardware0_rhsensor
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
1450271115.915908 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000
1450271115.917910 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000
1450271115.919906 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000
1450271115.921905 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000
1450271115.923906 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000
1450271115.925901 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000
1450271115.927914 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000
1450271115.929904 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000
1450271115.931911 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000
1450271115.933913 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000
Loading