pyqtgraph/tests/widgets/test_spinbox.py

47 lines
1.5 KiB
Python
Raw Normal View History

# -*- coding: utf-8 -*-
import pytest
2016-11-30 01:45:42 +00:00
import pyqtgraph as pg
2016-11-30 01:45:42 +00:00
pg.mkQApp()
def test_SpinBox_defaults():
2016-11-30 01:45:42 +00:00
sb = pg.SpinBox()
2016-12-08 18:14:18 +00:00
assert sb.opts['decimals'] == 6
2016-11-30 01:45:42 +00:00
assert sb.opts['int'] is False
@pytest.mark.parametrize("value,expected_text,opts", [
(0, '0', dict(suffix='', siPrefix=False, dec=False, int=False)),
(100, '100', dict()),
(1000000, '1e+06', dict()),
(1000, '1e+03', dict(decimals=2)),
(1000000, '1000000 V', dict(int=True, suffix='V')),
(12345678955, '12345678955', dict(int=True, decimals=100)),
(1.45e-9, '1.45e-09 A', dict(int=False, decimals=6, suffix='A', siPrefix=False)),
(1.45e-9, '1.45 nA', dict(int=False, decimals=6, suffix='A', siPrefix=True)),
(1.45, '1.45 PSI', dict(int=False, decimals=6, suffix='PSI', siPrefix=True)),
(1.45e-3, '1.45 mPSI', dict(int=False, decimals=6, suffix='PSI', siPrefix=True)),
(-2500.3427, '$-2500.34', dict(int=False, format='${value:0.02f}')),
(1000, '1 k', dict(siPrefix=True, suffix="")),
])
def test_SpinBox_formatting(value, expected_text, opts):
sb = pg.SpinBox(**opts)
sb.setValue(value)
assert sb.value() == value
assert sb.text() == expected_text
@pytest.mark.parametrize("suffix", ["", "V"])
def test_SpinBox_gui_set_value(suffix):
sb = pg.SpinBox(suffix=suffix)
sb.lineEdit().setText('0.1' + suffix)
sb.editingFinishedEvent()
assert sb.value() == 0.1
sb.lineEdit().setText('0.1 m' + suffix)
sb.editingFinishedEvent()
assert sb.value() == 0.1e-3