aboutsummaryrefslogtreecommitdiff
path: root/tests/test_toolkit_common.py
blob: b20ae537a8a8f1b70fb38b45387f2ab9f4bd80fb (plain)
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
42
43
44
45
46
47
48
from pytest import fixture
from pytestqt import qtbot
from avp.command import Command
from avp.toolkit import blockSignals, rgbFromString
from . import command


@fixture
def gotWarning():
    """Check if a function called log.warning"""
    import avp.toolkit.common as tk

    warning = False

    def gotWarning():
        nonlocal warning
        return warning

    class log:
        def warning(self, *args):
            nonlocal warning
            warning = True

    oldLog = tk.log
    tk.log = log()
    try:
        yield gotWarning
    finally:
        tk.log = oldLog


def test_blockSignals(qtbot, command):
    command.core.insertComponent(0, 0, command)
    comp = command.core.selectedComponents[0]
    assert comp.page.spinBox_scale.signalsBlocked() == False
    with blockSignals(comp.page.spinBox_scale):
        assert comp.page.spinBox_scale.signalsBlocked() == True
    assert comp.page.spinBox_scale.signalsBlocked() == False


def test_rgbFromString(gotWarning):
    assert rgbFromString("255,255,255") == (255, 255, 255)
    assert not gotWarning()


def test_rgbFromString_error(gotWarning):
    assert rgbFromString("255,255,256") == (255, 255, 255)
    assert gotWarning()