pyqtgraph/tests/widgets/test_spinbox.py
Kyle Sunden a472f8c5de
Remove all usage of python2_3.py (#1939)
* Remove all usage of python2_3.py

Technically these functions were exported at the top level of the library, this removes them without warning... If we want to we can bring them back for there, but I honestly don't think its needed, as we are py3 only now and have been for multiple releases.

This may introduce a number of 'useless cast' or similar but those were always happening anyway

This PR brought to you by sed

* Update varname in hdf example to avoid collision with builtin

* Clean up some leftover comments surrounding imports of compat code

* Unnecessary string casts

* Additional unnecessary casts

* syntax error fix

* more unnecessary casts

* Yet more unnecessary casts
2021-08-01 21:43:32 -07:00

47 lines
1.5 KiB
Python

# -*- coding: utf-8 -*-
import pytest
import pyqtgraph as pg
pg.mkQApp()
def test_SpinBox_defaults():
sb = pg.SpinBox()
assert sb.opts['decimals'] == 6
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