pyqtgraph/tests/widgets/test_combobox.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

44 lines
1.1 KiB
Python

import pyqtgraph as pg
pg.mkQApp()
def test_combobox():
cb = pg.ComboBox()
items = {'a': 1, 'b': 2, 'c': 3}
cb.setItems(items)
cb.setValue(2)
assert str(cb.currentText()) == 'b'
assert cb.value() == 2
# Clear item list; value should be None
cb.clear()
assert cb.value() == None
# Reset item list; value should be set automatically
cb.setItems(items)
assert cb.value() == 2
# Clear item list; repopulate with same names and new values
items = {'a': 4, 'b': 5, 'c': 6}
cb.clear()
cb.setItems(items)
assert cb.value() == 5
# Set list instead of dict
cb.setItems(list(items.keys()))
assert str(cb.currentText()) == 'b'
cb.setValue('c')
assert cb.value() == str(cb.currentText())
assert cb.value() == 'c'
cb.setItemValue('c', 7)
assert cb.value() == 7
if __name__ == '__main__':
cb = pg.ComboBox()
cb.show()
cb.setItems({'': None, 'a': 1, 'b': 2, 'c': 3})
def fn(ind):
print("New value: %s" % cb.value())
cb.currentIndexChanged.connect(fn)