def test_conversion_with_symbols(qtbot): widget = UnitEdit(text='1*b*mm') show(locals()) syms = widget.getSymbols() assert set(syms.keys()) == {'b'} expr = widget.getExpr() conv = units.convert_to(expr, units.meter) assert conv == units.meter * Symbol('b') / 1000 assert widget.convertTo('meter') == conv assert widget.convertTo(units.meter) == conv
def test_invalid_conversion(qtbot): widget = UnitEdit(text='(1*mm)*b') show(locals()) syms = widget.getSymbols() assert set(syms.keys()) == {'b'} assert (widget.convertTo(units.inch) - parseUnits('b*5*inch/127')).simplify() == 0 assert (widget.convertTo('kg') - parseUnits('b*mm')).simplify() == 0 assert (widget.convertTo(units.m * units.m) - parseUnits('b*m/1000')).simplify() == 0 assert (widget.convertTo(units.m) - parseUnits('b*m/1000')).simplify() == 0 widget = UnitEdit(text='2*mm') show(locals()) assert widget.getSymbols() == dict() widget.convertTo(units.inch) assert (widget.convertTo('kg') - parseUnits('2*mm')).simplify() == 0 assert (widget.convertTo(units.m * units.m) - parseUnits('1*m/500')).simplify() == 0 assert (widget.convertTo(units.m) - parseUnits('1*m/500')).simplify() == 0