File: test_sparse_datastore.py

package info (click to toggle)
pymodbus 3.8.6-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,720 kB
  • sloc: python: 14,867; makefile: 27; sh: 17
file content (48 lines) | stat: -rw-r--r-- 1,282 bytes parent folder | download
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
"""Test framers."""

import pytest

from pymodbus.datastore import ModbusSparseDataBlock


@pytest.mark.asyncio
async def test_check_async_sparsedatastore():
    """Test check frame."""
    data_in_block = {
        1: 6720,
        2: 130,
        30: [0x0D, 0xFE],
        105: [1, 2, 3, 4],
        20000: [45, 241, 48],
        20008: 38,
        48140: [0x4208, 0xCCCD],
    }
    datablock = ModbusSparseDataBlock(data_in_block)
    for key, entry in data_in_block.items():
        if isinstance(entry, int):
            entry = [entry]
        for value in entry:
            assert datablock.validate(key, 1)
            assert await datablock.async_getValues(key, 1) == [value]
            key += 1


def test_check_sparsedatastore():
    """Test check frame."""
    data_in_block = {
        1: 6720,
        2: 130,
        30: [0x0D, 0xFE],
        105: [1, 2, 3, 4],
        20000: [45, 241, 48],
        20008: 38,
        48140: [0x4208, 0xCCCD],
    }
    datablock = ModbusSparseDataBlock(data_in_block)
    for key, entry in data_in_block.items():
        if isinstance(entry, int):
            entry = [entry]
        for value in entry:
            assert datablock.validate(key, 1)
            assert datablock.getValues(key, 1) == [value]
            key += 1