import pytest
from unittest.mock import MagicMock, patch
from mhs5200 import MHS5200

@pytest.fixture
def mock_serial():
    with patch('serial.Serial') as mock:
        serial_instance = MagicMock()
        mock.return_value = serial_instance
        
        # Setup common mock behaviors
        serial_instance.is_open = True
        serial_instance.in_waiting = 1
        
        # Attach the class mock to the instance so tests can verify constructor calls
        serial_instance.mock_class = mock
        
        yield serial_instance

@pytest.fixture
def mhs(mock_serial):
    # Setup initial clear buffer behavior
    mock_serial.read_all.return_value = b''
    
    device = MHS5200('COM1')
    
    # Reset mock to clear initialization calls
    mock_serial.reset_mock()
    
    yield device
    
    device.close()
