def test_expr_error(qtbot): for e, safe, cause_error, ident in expr_safe_check: testLogger.debug( f"ex = {e}, safe = {safe}, error = {cause_error}, ident = {ident}") widget = ExprEdit(text=e) show(locals()) assert bool(widget.getError()) is cause_error if e == '': assert getCurrentColor(widget, 'Background').names[0] == \ widget.defaultColors['blank'][0] else: assert getCurrentColor(widget, 'Background').names[0] == \ widget.defaultColors['error' if cause_error else 'default'][0] widget = ExprEdit() show(locals()) for e, safe, cause_error, ident in expr_safe_check: widget.setText(e) assert bool(widget.getError()) is cause_error if e == '': assert getCurrentColor(widget, 'Background').names[0] == \ widget.defaultColors['blank'][0] else: assert getCurrentColor(widget, 'Background').names[0] == \ widget.defaultColors['error' if cause_error else 'default'][0]
def test_setError(qtbot): widget = EntryWidget() show(locals()) widget.setError(True) assert widget.getError() is True assert getCurrentColor( widget.lineEdit, 'Window').names[0] == widget.defaultColors['error'][0] widget.setError(False) assert widget.getError() is False assert getCurrentColor( widget.lineEdit, 'Window').names[0] == widget.defaultColors['blank'][0]
def test_constructor_text(qtbot): widget = ExprEdit(text='text') show(locals()) assert bool(widget.getError()) is False assert getCurrentColor( widget, 'Background').names[0] == widget.defaultColors['default'][0] assert list(widget.getSymbols().values()) == [Symbol('text')]
def test_constructor(qtbot): widget = ExprEdit() show(locals()) assert widget.getError() is None assert getCurrentColor( widget, 'Background').names[0] == widget.defaultColors['blank'][0] assert dict() == widget.getSymbols()
def test_constructor_text(qtbot): widget = UnitEdit(text='text') show(locals()) assert bool(widget.getError()) is False assert getCurrentColor( widget, 'Background').names[0] == widget.defaultColors['default'][0] assert set(widget.getSymbols().keys()) == {'text'}
def test_basic_constructor(qtbot): widget = SymbolEdit() show(locals()) assert widget.getError() assert getCurrentColor( widget, 'Background').names[0] == widget.defaultColors['error'][0] assert widget.getExpr() is None
def test_errorCheck_live(qtbot): widget = EntryWidget(errorCheck=check_error_typed) show(locals()) logging.debug('typing...') qtbot.keyClicks(widget.lineEdit, 'erro') assert widget.getError() is False qtbot.keyClicks(widget.lineEdit, 'r') logging.debug('finished typing...') assert widget.getError() == 'ERROR' assert getCurrentColor( widget.lineEdit, 'Window').names[0] == widget.defaultColors['error'][0] qtbot.keyPress(widget.lineEdit, QtCore.Qt.Key_Backspace) assert widget.getError() is False assert getCurrentColor( widget.lineEdit, 'Window').names[0] == widget.defaultColors['default'][0]
def test_onOptionChanged(qtbot): widget = EntryWidget(options=test_options_colors) show(locals()) widget.optionChanged.connect(lambda: change_color_on_option(widget)) widget.setSelected(test_options_colors[1]) assert getCurrentColor(widget.lineEdit, 'Window')[0][0] == test_options_colors[1] widget.setSelected(test_options_colors[0]) assert getCurrentColor(widget.lineEdit, 'Window')[0][0] == test_options_colors[0] widget.setSelected(test_options_colors[2]) assert getCurrentColor(widget.lineEdit, 'Window')[0][0] == test_options_colors[2]
def test_constructor_blank(qtbot): widget = SympyEntryWidget() show(locals()) testLogger.debug((widget.getError(), widget.lineEdit.getError(), widget.lineEdit._error, widget.lineEdit._expr)) assert widget.getError() is None assert getCurrentColor( widget.lineEdit, 'Background').names[0] == widget.defaultColors['blank'][0]
def test_errorCheck_with_combobox(qtbot): widget = EntryWidget(errorCheck=check_text_matches_option, options=['a', 'b']) show(locals()) qtbot.keyClicks(widget.lineEdit, 'b') assert widget.getError() is False qtbot.keyPress(widget.lineEdit, QtCore.Qt.Key_Backspace) qtbot.keyPress(widget.lineEdit, 'a') assert widget.getError() is True assert getCurrentColor( widget.lineEdit, 'Window').names[0] == widget.defaultColors['error'][0] widget.setSelected('b') assert widget.getError() is False qtbot.keyPress(widget.lineEdit, QtCore.Qt.Key_Backspace) qtbot.keyPress(widget.lineEdit, 'b') assert widget.getError() is True assert getCurrentColor( widget.lineEdit, 'Window').names[0] == widget.defaultColors['error'][0]
def test_constructor_text(qtbot): widget = SympyEntryWidget(text='text*mm') show(locals()) testLogger.debug((widget.getError(), widget.lineEdit.getError(), widget.lineEdit._error, widget.lineEdit._expr)) assert widget.getError() is False assert list(widget.getSymbols().keys()) == ['text'] assert getCurrentColor( widget.lineEdit, 'Background').names[0] == widget.defaultColors['default'][0] widget = SympyEntryWidget(text='text') show(locals()) testLogger.debug((widget.getError(), widget.lineEdit.getError(), widget.lineEdit._error, widget.lineEdit._expr)) assert widget.getError() assert getCurrentColor( widget.lineEdit, 'Background').names[0] == widget.defaultColors['error'][0]
def test_constructor_units(qtbot): widget = UnitEdit(text='2.0*mm') show(locals()) assert widget.getError() is False assert getCurrentColor( widget, 'Background').names[0] == widget.defaultColors['default'][0] assert widget.getSymbols() == dict() assert widget.getExpr().atoms(units.Unit) == {units.mm} assert widget.getDimension() == units.Dimension('length') assert widget.getMagnitude() == 2 assert widget.getUnits() == units.millimeter assert widget.getValue() == widget.getUnits() * widget.getMagnitude()
def test_text_changes_value(qtbot): widget = SympyEntryWidget(text='1*mm + 1*inch', options='length') show(locals()) assert widget.getError() is False assert (widget.convertTo(units.inch) - (132 / 127) * units.inch) == 0.0 * units.inch qtbot.keyPress(widget.lineEdit, QtCore.Qt.Key_Home) qtbot.keyClicks(widget.lineEdit, '1') assert (widget.convertTo(units.inch) - (182 / 127) * units.inch) == 0.0 * units.inch assert quantity_simplify(widget.getValue() - (182 / 127 * units.inch)) == 0 qtbot.keyPress(widget.lineEdit, 'b') assert widget.getError() assert getCurrentColor( widget.lineEdit, 'Window').names[0] == widget.defaultColors['error'][0]