22 lines
820 B
Python
22 lines
820 B
Python
import pytest
|
|
from unittest.mock import MagicMock, patch
|
|
from m2m.nbiot import factory
|
|
from m2m.nbiot.module_bg96 import ModuleBG96
|
|
|
|
@patch('m2m.serial.serial_port.serial.Serial')
|
|
def test_factory_creates_bg96(mock_serial_cls):
|
|
"""Verify that the factory correctly instantiates a BG96 module with a mocked serial port."""
|
|
# Setup mock to avoid hardware dependency
|
|
mock_inst = MagicMock()
|
|
mock_serial_cls.return_value = mock_inst
|
|
|
|
module = factory('BG96', '/dev/ttyUSB0')
|
|
|
|
assert isinstance(module, ModuleBG96)
|
|
# Corrected attribute access path
|
|
assert module.s_port._port_name == '/dev/ttyUSB0'
|
|
|
|
def test_factory_invalid_chipset():
|
|
"""Verify that an invalid chipset raises a ValueError."""
|
|
with pytest.raises(ValueError):
|
|
factory('INVALID_CHIPSET', '/dev/ttyUSB0')
|