Skip to content

Commit 38421f3

Browse files
authored
Test coverage simulator 100%. (#2763)
1 parent 9bbf344 commit 38421f3

File tree

5 files changed

+15
-15
lines changed

5 files changed

+15
-15
lines changed

pymodbus/simulator/simcore.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def build_config(cls, devices: list[SimDevice]) -> SimCore:
3434
if cfg_block:
3535
cls.build_block(cfg_block)
3636

37-
#core.devices[dev.id] = (
37+
core.devices[dev.id] = dev
3838
# block_coil,
3939
# block_direct,
4040
# block_holding,

test/datastore/test_simulator_datastore.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -168,13 +168,6 @@ class TestDatastoreSimulator:
168168
# 48 MAX before repeat
169169
]
170170

171-
@staticmethod
172-
@pytest.fixture(name="use_port")
173-
def get_port_in_class(base_ports):
174-
"""Return next port."""
175-
base_ports[__class__.__name__] += 1
176-
return base_ports[__class__.__name__]
177-
178171
@classmethod
179172
def custom_action1(cls, _inx, _cell):
180173
"""Test action."""

test/server/test_simulator.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import pytest
99

1010
from pymodbus.client import AsyncModbusTcpClient
11-
from pymodbus.datastore import ModbusSimulatorContext
1211
from pymodbus.datastore.simulator import Cell, CellType
1312
from pymodbus.server import ModbusSimulatorServer
1413
from pymodbus.server.simulator.main import run_main
@@ -199,11 +198,6 @@ def copy_default_device(self):
199198
"""Copy default device."""
200199
return copy.deepcopy(self.default_device)
201200

202-
@pytest.fixture(name="simulator")
203-
def create_simulator(self, device):
204-
"""Create simulator context."""
205-
return ModbusSimulatorContext(device, self.custom_actions)
206-
207201
@pytest.fixture(name="server")
208202
def copy_default_server(self, use_port):
209203
"""Create simulator context."""

test/simulator/test_simcore.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
"""Test SimCore."""
22

3+
import pytest
34

4-
from pymodbus.simulator import SimCore
5+
from pymodbus.simulator import SimCore, SimData, SimDevice
56

67

78
class TestSimCore:
@@ -10,3 +11,14 @@ class TestSimCore:
1011
def test_instanciate(self):
1112
"""Test that simdata can be objects."""
1213
SimCore()
14+
15+
def test_build_block(self):
16+
"""Test that simdata can be objects."""
17+
SimCore.build_block(None)
18+
19+
def test_build_config(self):
20+
"""Test that simdata can be objects."""
21+
device = SimDevice(17, block_shared=[SimData(0)])
22+
SimCore.build_config([device])
23+
with pytest.raises(TypeError):
24+
SimCore.build_config([device, device])

test/simulator/test_simdata.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ def test_simdata_datatype(self, datatype):
3838
(1.0, SimDataType.FLOAT32),
3939
(11, SimDataType.REGISTERS),
4040
(True, SimDataType.BITS),
41+
(17, SimDataType.DEFAULT),
4142
])
4243
def test_simdata_value_ok(self, value, value_type):
4344
"""Test simdata value."""

0 commit comments

Comments
 (0)