Exemple #1
0
def test_ReadCommands_errThatsNotEndOfQueue(cm):
    card = Mock()
    card.Transaction.return_value = {
        "err": "error message that does NOT represent end of queue"
    }

    with pytest.raises(
            Exception,
            match="error message that does NOT represent end of queue"):
        attn.ReadCommands(card)

    cm.Enqueue.assert_not_called()
Exemple #2
0
def test_ReadCommands_noNoteBody(cm):
    card = Mock()
    card.Transaction.side_effect = [{
        "field": "value"
    }, {
        "err": " {note-noexist} "
    }]

    attn.ReadCommands(card)

    cm.Enqueue.assert_not_called()
    assert card.Transaction.call_count == 2
Exemple #3
0
def test_ReadCommands_noCommands(cm):
    card = Mock()
    card.Transaction.return_value = {"err": " {note-noexist} "}

    attn.ReadCommands(card)

    cm.Enqueue.assert_not_called()
    card.Transaction.assert_called_once_with({
        "req": "note.get",
        "file": "commands.qi",
        "delete": True
    })
Exemple #4
0
def test_ReadCommands_oneCommandMultipleArgs(cm):
    card = Mock()
    card.Transaction.side_effect = [{
        "body": {
            "func": ["arg1", "arg2"]
        }
    }, {
        "err": " {note-noexist} "
    }]

    attn.ReadCommands(card)

    cm.Enqueue.assert_called_once_with("func", ("arg1", "arg2"))
    assert card.Transaction.call_count == 2
Exemple #5
0
def test_ReadCommands_oneCommandOneStringArg(cm):
    card = Mock()
    card.Transaction.side_effect = [{
        "body": {
            "print": "abc"
        }
    }, {
        "err": " {note-noexist} "
    }]

    attn.ReadCommands(card)

    cm.Enqueue.assert_called_once_with("print", ("abc", ))
    assert card.Transaction.call_count == 2
Exemple #6
0
def test_ReadCommands_multipleCommandsMultipleArgs(cm):
    card = Mock()
    card.Transaction.side_effect = [{
        "body": {
            "func1": ["arg1", "arg2"],
            "func2": "arg3"
        }
    }, {
        "err": " {note-noexist} "
    }]

    attn.ReadCommands(card)

    callList = cm.Enqueue.call_args_list
    assert callList[0].args == ("func1", ("arg1", "arg2"))
    assert callList[1].args == ("func2", ("arg3", ))
    assert card.Transaction.call_count == 2
Exemple #7
0
def test_ReadCommands_oneCommandDictArg(cm):
    card = Mock()
    card.Transaction.side_effect = [{
        "body": {
            "count": {
                "min": 1,
                "inc": 3,
                "max": 7
            }
        }
    }, {
        "err": " {note-noexist} "
    }]

    attn.ReadCommands(card)

    cm.Enqueue.assert_called_once_with("count", ({
        "min": 1,
        "inc": 3,
        "max": 7
    }, ))
    assert card.Transaction.call_count == 2
Exemple #8
0
    if config.EnableDebug:
        log.setLevel(logging.DEBUG)
        ch.setLevel(logging.DEBUG)

    log.info(f"Running: {__file__}")

    message = f"\nProduct: {config.ProductUID}\nHost: {config.HubHost}\nDebug: {config.EnableDebug}\nConnection Port Type:{config.PortType}\nPort name: {config.PortName}\n"
    log.info(message)

    log.debug(f"Connecting to Notecard using {config.PortType} port type")
    card = connectNotecard(config)

    log.debug("Configuring Notecard Hub connection")
    configureNotecard(card, productUID=config.ProductUID, host=config.HubHost)

    attn.ReadCommands(card)

    def attnIsrHandler(channel):
        global AttnFired
        AttnFired = True

    GPIO.add_event_detect(gpioAttnPin, GPIO.RISING, callback=attnIsrHandler)

    attn.Initialize(card)

    # Enables killing this script via Ctrl-C
    signal.signal(signal.SIGINT, signal_handler)

    startMainLoop()