Exemplo n.º 1
0
def test_register_invalid_val():
    reg = RegsRegister(TEST_REG_NAME, TEST_REG_OFFSET, TEST_REG_WIDTH,
                       TEST_REG_DESCR, TEST_REG_REV, TEST_REG_ACCESS)

    reg.set_value("Invalid")
    assert reg.get_value() == b''

    reg.set_value([1, 2])
    assert reg.get_value() == b''
Exemplo n.º 2
0
def test_basic_regs(tmpdir):
    """Basic test of registers class."""
    regs = Registers(TEST_DEVICE_NAME)

    assert regs.dev_name == TEST_DEVICE_NAME

    reg1 = RegsRegister(
        TEST_REG_NAME,
        TEST_REG_OFFSET,
        TEST_REG_WIDTH,
        TEST_REG_DESCR,
        TEST_REG_REV,
        TEST_REG_ACCESS,
    )

    with pytest.raises(SPSDKRegsErrorRegisterNotFound):
        regs.find_reg("NonExisting")

    # The Registers MUST return empty array
    assert regs.get_reg_names() == []

    with pytest.raises(SPSDKError):
        regs.remove_register("String")

    with pytest.raises(ValueError):
        regs.remove_register(reg1)

    # Now we could do tests with a register added to list
    regs.add_register(reg1)

    regs.remove_register_by_name(["String"])

    assert TEST_REG_NAME in regs.get_reg_names()

    regt = regs.find_reg(TEST_REG_NAME)

    assert regt == reg1

    with pytest.raises(SPSDKError):
        regs.add_register("Invalid Parameter")

    regt.set_value(TEST_REG_VALUE)
    assert reg1.get_value() == TEST_REG_VALUE

    filename = os.path.join(tmpdir, TEST_XML_FILE)
    regs.write_xml(filename)
    assert os.path.isfile(filename)

    printed_str = str(regs)

    assert TEST_DEVICE_NAME in printed_str
    assert TEST_REG_NAME in printed_str

    regs.remove_register_by_name([TEST_REG_NAME])

    with pytest.raises(SPSDKRegsErrorRegisterNotFound):
        regs.find_reg(TEST_REG_NAME)
        assert False
Exemplo n.º 3
0
def test_register_invalid_val():
    """Invalid value register test."""
    reg = RegsRegister(
        TEST_REG_NAME,
        TEST_REG_OFFSET,
        TEST_REG_WIDTH,
        TEST_REG_DESCR,
        TEST_REG_REV,
        TEST_REG_ACCESS,
    )

    val = reg.get_value()
    with pytest.raises(SPSDKError):
        reg.set_value("Invalid")
    assert reg.get_value() == val

    with pytest.raises(SPSDKError):
        reg.set_value([1, 2])
    assert reg.get_value() == val