pyqtgraph/tests/widgets/test_spinbox.py
Ogi Moore a6971c768d Move and Update test-data repo into pyqtgraph repo
To reduce complexity, and make it easier to add more images and tests,
the images in the `test-data` repository should be merged with the main
repository.  Furthermore, we can remove a lot of the subprocess work in
the image_testing.py file, as we no longer need to have it interact with
git.

The images are not the same.  Images were regenerated with Qt6, and now
have proper big and little endian handling thanks to @pijyoi

Second commit is a slightly modified variant of
2e135ab282d6007b34a3854921be54d0e9efb241 authored by @pijyoi
it is to convert qimages to RGBA8888 for testing.  Image
files were regenerated images for the big/little handling

Fixed issue with bogus test from test_NonUniformImage and generated a
new image
2021-05-31 21:05:00 -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 pg.asUnicode(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