Compare commits

..

2 Commits

Author SHA1 Message Date
Nicolas 5aab2d6d74 Escaping for f-strings fixed 2025-05-13 09:39:05 +02:00
Nicolas d748553711 github action for CI added 2025-05-13 09:33:22 +02:00
5 changed files with 46 additions and 7 deletions

View File

@ -14,6 +14,7 @@ exclude =
dist,
.conda
.venv
venv
# Enable specific plugins or options
# Example: Enabling flake8-docstrings

38
.github/workflows/ci.yml vendored Normal file
View File

@ -0,0 +1,38 @@
name: CI Pipeline
on:
push:
branches: [main]
pull_request:
branches: [main]
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.10", 3.11, 3.12, 3.13]
steps:
- name: Check out code
uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install -e .[dev]
- name: Lint code with flake8
run: flake8
- name: Type checking with mypy
run: mypy
- name: Run tests with pytest
run: pytest

View File

@ -45,8 +45,8 @@ class BusTerminal():
@classmethod
def select(cls, bus_coupler: 'BusCoupler', terminal_number: int = 0) -> 'BusTerminal':
terminal_list = [bt for bt in bus_coupler.bus_terminals if isinstance(bt, cls)]
assert terminal_list, f'No instance of {cls.__name__} configured at this BusCoupler'
assert 0 <= terminal_number < len(terminal_list), f'Out of range, select in range: 0..{len(terminal_list) - 1}'
assert terminal_list, f"No instance of {cls.__name__} configured at this BusCoupler"
assert 0 <= terminal_number < len(terminal_list), f"Out of range, select in range: 0..{len(terminal_list) - 1}"
return terminal_list[terminal_number]
@ -283,7 +283,7 @@ class BusCoupler():
terminal_classes.append(element)
for terminal_class in terminal_classes:
assert _is_bus_terminal(terminal_class), f'{terminal_class} is not a bus terminal'
assert _is_bus_terminal(terminal_class), f"{terminal_class} is not a bus terminal"
def get_para(key: str) -> int:
return terminal_class.parameters.get(key, 0)

View File

@ -451,7 +451,7 @@ class SimpleModbusClient:
return bytes()
if self.debug:
print(f'<- Received: {' '.join(hex(b) for b in buffer)}')
print(f"<- Received: {' '.join(hex(b) for b in buffer)}")
return buffer
@ -471,7 +471,7 @@ class SimpleModbusClient:
try:
self._socket.sendall(data)
if self.debug:
print(f'-> Send: {' '.join(hex(b) for b in data)}')
print(f"-> Send: {' '.join(hex(b) for b in data)}")
return len(data)
except socket.error:
self.last_error = 'sending data failed'
@ -532,7 +532,7 @@ class SimpleModbusClient:
return self.close()
if data[0] > 0x80:
self.last_error = f'return error: {_modbus_exceptions.get(data[1], '')} ({data[1]})'
self.last_error = f"return error: {_modbus_exceptions.get(data[1], '')} ({data[1]})"
if self.debug:
print(self.last_error)
return bytes()

View File

@ -14,7 +14,7 @@ def test_against_old_traces():
# dummy modbus send function
def debug_send_dummy(data: bytes) -> int:
print(f'-> Send: {' '.join(hex(b) for b in data)}')
print(f"-> Send: {' '.join(hex(b) for b in data)}")
for b in data:
debug_data.append(f"{b:02X}")
return len(data)