Skip to content

Commit 93817b1

Browse files
committed
Keep one test of mock.py
1 parent f3ab217 commit 93817b1

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

clickplc/tests/test_driver.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""Test the driver correctly parses a tags file and responds with correct data."""
22
import asyncio
33
import contextlib
4+
from unittest import mock
45

56
import pytest
67

@@ -10,6 +11,7 @@
1011
from pymodbus.server.async_io import ModbusTcpServer
1112

1213
from clickplc import ClickPLC, command_line
14+
from clickplc.mock import ClickPLC as MockClickPLC
1315

1416
# Test against pymodbus simulator
1517
ADDRESS = '127.0.0.1'
@@ -20,7 +22,7 @@
2022

2123
@pytest.fixture(scope='session', autouse=autouse)
2224
async def _sim():
23-
"""Start a modbus server simulator."""
25+
"""Start a modbus server and datastore."""
2426
from pymodbus.datastore import (
2527
ModbusSequentialDataBlock,
2628
ModbusServerContext,
@@ -81,6 +83,18 @@ def test_driver_cli(capsys):
8183
assert 'df100' in captured.out
8284

8385

86+
@mock.patch('clickplc.ClickPLC', MockClickPLC)
87+
def test_driver_cli_tags_mock(capsys):
88+
"""Confirm the (mocked) commandline interface works without a tags file."""
89+
command_line([ADDRESS, 'clickplc/tests/plc_tags.csv'])
90+
captured = capsys.readouterr()
91+
assert 'P_101' in captured.out
92+
assert 'VAHH_101_OK' in captured.out
93+
assert 'TI_101' in captured.out
94+
with pytest.raises(SystemExit):
95+
command_line([ADDRESS, 'tags', 'bogus'])
96+
97+
8498
def test_driver_cli_tags(capsys):
8599
"""Confirm the commandline interface works with a tags file."""
86100
command_line([ADDRESS, 'clickplc/tests/plc_tags.csv'])

0 commit comments

Comments
 (0)