示例#1
0
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
示例#2
0
def test_embed_widgets(qtbot):
    from PyQt5.QtWidgets import QVBoxLayout, QWidget
    window = QWidget()
    layout = QVBoxLayout(window)
    layout.addWidget(EntryWidget())
    layout.addWidget(EntryWidget())
    window.setLayout(layout)
    show({'qtbot': qtbot, 'widget': window})
示例#3
0
def test_constructor_optionFixed(qtbot):
    widget = EntryWidget(optionFixed=True)
    show(locals())
    assert widget.comboBox.isEnabled() is False
    assert widget.optionFixed() is True

    widget = EntryWidget(optionFixed=False)
    show(locals())
    assert widget.comboBox.isEnabled() is True
    assert widget.optionFixed() is False
示例#4
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]
示例#5
0
def test_hasError(qtbot):
    widget = EntryWidget()
    widget.hasError.connect(lambda: set_title_on_error(widget))
    show(locals())

    assert widget.getError() is False
    widget.setError(False)
    assert widget.getError() is False
    widget.setError(True)
    assert widget.windowTitle() == 'ERROR'
    widget.clearError()
    assert widget.getError() is None
示例#6
0
def test_setFixedOption(qtbot):
    widget = EntryWidget()
    show(locals())
    widget.setOptionFixed(True)
    assert widget.comboBox.isEnabled() is False
    assert widget.optionFixed() is True

    widget = EntryWidget()
    show(locals())
    widget.setOptionFixed(False)
    assert widget.comboBox.isEnabled() is True
    assert widget.optionFixed() is False
示例#7
0
def test_setEnabled(qtbot):
    widget = EntryWidget()
    show(locals())
    widget.setEnabled(False)
    assert widget.lineEdit.isEnabled() is False
    assert widget.isReadOnly() is False
    assert widget.comboBox.isEnabled() is False
    assert widget.optionFixed() is True

    widget.setEnabled(True)
    assert widget.lineEdit.isEnabled() is True
    assert widget.isReadOnly() is False
    assert widget.comboBox.isEnabled() is True
    assert widget.optionFixed() is False
示例#8
0
def test_constructor_readOnly(qtbot):
    widget = EntryWidget(readOnly=True)
    show(locals())
    assert widget.lineEdit.isReadOnly() is True
    assert widget.isReadOnly() is True
    assert widget.comboBox.isEnabled() is False
    assert widget.optionFixed() is True

    widget = EntryWidget(readOnly=False)
    show(locals())
    assert widget.lineEdit.isReadOnly() is False
    assert widget.isReadOnly() is False
    assert widget.comboBox.isEnabled() is True
    assert widget.optionFixed() is False
示例#9
0
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]
示例#10
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]
示例#11
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]
示例#12
0
def test_symbol_name_error(qtbot):
    for e in expr_safe_check:
        logging.debug(e)
        widget = SymbolEdit(text=e[0])
        show(locals())
        assert bool(widget.getError()) is not e[3]
        if bool(widget.getError()):
            assert widget.getExpr() is None
        else:
            assert widget.getExpr() == Symbol(e[0])

    widget = SymbolEdit()
    for e in expr_safe_check:
        logging.debug(e)
        widget.setText(e[0])
        assert bool(widget.getError()) is not e[3]
        if bool(widget.getError()):
            assert widget.getExpr() is None
        else:
            assert widget.getExpr() == Symbol(e[0])
示例#13
0
def test_constructor_options(qtbot):
    widget = EntryWidget(options=test_options_good)
    show(locals())
    assert widget.getOptions() == {k: k for k in test_options_good}
    assert widget.getSelected() == test_options_good[0]
示例#14
0
def test_constructor_basic(qtbot):
    widget = EntryWidget()
    show(locals())
示例#15
0
def test_setOptions(qtbot):
    widget = EntryWidget()
    show(locals())
    widget.setOptions(test_options_good)
    assert widget.getOptions() == {k: k for k in test_options_good}
    assert widget.getSelected() == test_options_good[0]