File: test_quantity.py

package info (click to toggle)
superqt 0.7.7-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,320 kB
  • sloc: python: 9,108; makefile: 16; sh: 12
file content (41 lines) | stat: -rw-r--r-- 1,246 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
from pint import Quantity

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


def test_change_qquantity_value(qtbot):
    w = QQuantity()
    qtbot.addWidget(w)
    assert w.value() == Quantity(0)
    w.setValue(Quantity("1 meter"))
    assert w.value() == Quantity("1 meter")