feat: add Quantity widget (using pint) (#126)

* wip

* simplified quantity widget

* fix example

* more docs

* add test

* update docs

* try to avoid overflow

* reduce again
This commit is contained in:
Talley Lambert
2022-10-10 08:22:52 -04:00
committed by GitHub
parent 9f9dab6f3b
commit abf544cf0e
7 changed files with 319 additions and 3 deletions

31
tests/test_quantity.py Normal file
View File

@@ -0,0 +1,31 @@
from superqt import QQuantity
def test_qquantity(qtbot):
w = QQuantity(1, "m")
qtbot.addWidget(w)
assert w.value() == 1 * w.unitRegistry().meter
assert w.magnitude() == 1
assert w.units() == w.unitRegistry().meter
assert w.text() == "1 meter"
w.setUnits("cm")
assert w.value() == 100 * w.unitRegistry().centimeter
assert w.magnitude() == 100
assert w.units() == w.unitRegistry().centimeter
assert w.text() == "100.0 centimeter"
w.setMagnitude(10)
assert w.value() == 10 * w.unitRegistry().centimeter
assert w.magnitude() == 10
assert w.units() == w.unitRegistry().centimeter
assert w.text() == "10 centimeter"
w.setValue(1 * w.unitRegistry().meter)
assert w.value() == 1 * w.unitRegistry().meter
assert w.magnitude() == 1
assert w.units() == w.unitRegistry().meter
assert w.text() == "1 meter"
w.setUnits(None)
assert w.isDimensionless()
assert w.unitsComboBox().currentText() == "-----"
assert w.magnitude() == 1