Skip to content

Commit

Permalink
Fix test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
dhoomakethu committed Feb 11, 2019
1 parent e5c2615 commit f66f464
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 9 deletions.
3 changes: 2 additions & 1 deletion .coveragerc
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
[run]
omit =
pymodbus/repl/*
pymodbus/repl/*
pymodbus/internal/*
6 changes: 0 additions & 6 deletions pymodbus/framer/ascii_framer.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
import struct
import socket
from binascii import b2a_hex, a2b_hex

from pymodbus.exceptions import ModbusIOException
from pymodbus.utilities import checkLRC, computeLRC
from pymodbus.framer import ModbusFramer, FRAME_HEADER, BYTE_ORDER

# Python 2 compatibility.
try:
TimeoutError
except NameError:
TimeoutError = socket.timeout

ASCII_FRAME_HEADER = BYTE_ORDER + FRAME_HEADER

Expand Down
29 changes: 27 additions & 2 deletions test/test_framers.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,22 @@
else: # Python 2
from mock import Mock


@pytest.fixture
def rtu_framer():
return ModbusRtuFramer(ClientDecoder())


@pytest.fixture
def ascii_framer():
return ModbusAsciiFramer(ClientDecoder())


@pytest.fixture
def binary_framer():
return ModbusBinaryFramer(ClientDecoder())


@pytest.mark.parametrize("framer", [ModbusRtuFramer,
ModbusAsciiFramer,
ModbusBinaryFramer,
Expand Down Expand Up @@ -116,9 +120,12 @@ def test_populate_result(rtu_framer):
assert result.unit_id == 255


def test_process_incoming_packet(rtu_framer):
@pytest.mark.parametrize('framer', [ascii_framer, rtu_framer, binary_framer])
def test_process_incoming_packet(framer):
def cb(res):
return res
# data = b''
# framer.processIncomingPacket(data, cb, unit=1, single=False)


def test_build_packet(rtu_framer):
Expand Down Expand Up @@ -160,4 +167,22 @@ def cb(res):

def test_get_raw_frame(rtu_framer):
rtu_framer._buffer = b'\x00\x01\x00\x01\x00\n\xec\x1c'
assert rtu_framer.getRawFrame() == rtu_framer._buffer
assert rtu_framer.getRawFrame() == rtu_framer._buffer


def test_validate_unit_id(rtu_framer):
rtu_framer.populateHeader( b'\x00\x01\x00\x01\x00\n\xec\x1c')
assert rtu_framer._validate_unit_id([0], False)
assert rtu_framer._validate_unit_id([1], True)


@pytest.mark.parametrize('data', [b':010100010001FC\r\n',
b''])
def test_decode_ascii_data(ascii_framer, data):
data = ascii_framer.decode_data(data)
assert isinstance(data, dict)
if data:
assert data.get("unit") == 1
assert data.get("fcode") == 1
else:
assert not data

0 comments on commit f66f464

Please sign in to comment.