Run tests on multiple python versions (#566)

This commit is contained in:
J. Nick Koston 2023-10-11 12:52:19 -10:00 committed by GitHub
parent 96a448b02c
commit 275ca3a660
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 31 additions and 31 deletions

View File

@ -15,40 +15,32 @@ concurrency:
jobs: jobs:
ci: ci:
name: ${{ matrix.name }} name: ${{ matrix.name }} py ${{ matrix.python-version }} on ${{ matrix.os }}
runs-on: ubuntu-latest runs-on: ${{ matrix.os }}
strategy: strategy:
fail-fast: false fail-fast: false
matrix: matrix:
include: python-version:
- id: flake8 - "3.9"
name: Lint with flake8 - "3.10"
- id: pylint - "3.11"
name: Lint with pylint - "3.12"
- id: black os:
name: Check formatting with black - ubuntu-latest
- id: isort
name: Check import order with isort
- id: mypy
name: Check typing with mypy
- id: pytest
name: Run tests with pytest
- id: protoc
name: Check protobuf files match
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
- name: Set up Python - name: Set up Python
uses: actions/setup-python@v4 uses: actions/setup-python@v4
id: python id: python
with: with:
python-version: '3.9' python-version: ${{ matrix.python-version }}
- name: Get pip cache dir - name: Get pip cache dir
id: pip-cache id: pip-cache
run: | run: |
echo "dir=$(pip cache dir)" >> $GITHUB_OUTPUT echo "dir=$(pip cache dir)" >> $GITHUB_OUTPUT
- name: Restore PIP cache - name: Restore PIP cache
uses: actions/cache@v3.3.2 uses: actions/cache@v3
with: with:
path: ${{ steps.pip-cache.outputs.dir }} path: ${{ steps.pip-cache.outputs.dir }}
key: pip-${{ steps.python.outputs.python-version }}-${{ hashFiles('requirements.txt', 'requirements_test.txt') }} key: pip-${{ steps.python.outputs.python-version }}-${{ hashFiles('requirements.txt', 'requirements_test.txt') }}
@ -58,7 +50,6 @@ jobs:
run: | run: |
pip3 install -r requirements.txt -r requirements_test.txt pip3 install -r requirements.txt -r requirements_test.txt
pip3 install -e . pip3 install -e .
- name: Register problem matchers - name: Register problem matchers
run: | run: |
echo "::add-matcher::.github/workflows/matchers/flake8.json" echo "::add-matcher::.github/workflows/matchers/flake8.json"
@ -68,17 +59,22 @@ jobs:
echo "::add-matcher::.github/workflows/matchers/pytest.json" echo "::add-matcher::.github/workflows/matchers/pytest.json"
- run: flake8 aioesphomeapi - run: flake8 aioesphomeapi
if: ${{ matrix.id == 'flake8' }} name: Lint with flake8
if: ${{ matrix.python-version == '3.11' }}
- run: pylint aioesphomeapi - run: pylint aioesphomeapi
if: ${{ matrix.id == 'pylint' }} name: Lint with pylint
if: ${{ matrix.python-version == '3.11' }}
- run: black --check --diff --color aioesphomeapi tests - run: black --check --diff --color aioesphomeapi tests
if: ${{ matrix.id == 'black' }} name: Check formatting with black
if: ${{ matrix.python-version == '3.11' }}
- run: isort --check --diff aioesphomeapi tests - run: isort --check --diff aioesphomeapi tests
if: ${{ matrix.id == 'isort' }} name: Check import order with isort
if: ${{ matrix.python-version == '3.11' }}
- run: mypy aioesphomeapi - run: mypy aioesphomeapi
if: ${{ matrix.id == 'mypy' }} name: Check typing with mypy
if: ${{ matrix.python-version == '3.11' }}
- run: pytest -vv --tb=native tests - run: pytest -vv --tb=native tests
if: ${{ matrix.id == 'pytest' }} name: Run tests with pytest
- run: | - run: |
docker run \ docker run \
-v "$PWD":/aioesphomeapi \ -v "$PWD":/aioesphomeapi \
@ -89,4 +85,5 @@ jobs:
echo 'docker run -v "$PWD":/aioesphomeapi ghcr.io/esphome/aioesphomeapi-proto-builder:latest' echo 'docker run -v "$PWD":/aioesphomeapi ghcr.io/esphome/aioesphomeapi-proto-builder:latest'
exit 1 exit 1
fi fi
if: ${{ matrix.id == 'protoc' }} name: Check protobuf files match
if: ${{ matrix.python-version == '3.11' }}

View File

@ -322,6 +322,7 @@ class APIConnection:
fh: APIPlaintextFrameHelper | APINoiseFrameHelper fh: APIPlaintextFrameHelper | APINoiseFrameHelper
loop = self._loop loop = self._loop
process_packet = self._process_packet_factory() process_packet = self._process_packet_factory()
assert self._socket is not None
if self._params.noise_psk is None: if self._params.noise_psk is None:
_, fh = await loop.create_connection( _, fh = await loop.create_connection(
@ -334,9 +335,11 @@ class APIConnection:
sock=self._socket, sock=self._socket,
) )
else: else:
noise_psk = self._params.noise_psk
assert noise_psk is not None
_, fh = await loop.create_connection( _, fh = await loop.create_connection(
lambda: APINoiseFrameHelper( lambda: APINoiseFrameHelper(
noise_psk=self._params.noise_psk, noise_psk=noise_psk,
expected_name=self._params.expected_name, expected_name=self._params.expected_name,
on_pkt=process_packet, on_pkt=process_packet,
on_error=self._report_fatal_error, on_error=self._report_fatal_error,

View File

@ -108,12 +108,12 @@ async def test_connect(conn, resolve_host, socket_socket, event_loop):
async def test_requires_encryption_propagates(conn: APIConnection): async def test_requires_encryption_propagates(conn: APIConnection):
loop = asyncio.get_event_loop() loop = asyncio.get_event_loop()
protocol = _get_mock_protocol(conn) protocol = _get_mock_protocol(conn)
with patch.object(loop, "create_connection") as create_connection, patch.object( with patch.object(loop, "create_connection") as create_connection:
protocol, "perform_handshake"
):
create_connection.return_value = (MagicMock(), protocol) create_connection.return_value = (MagicMock(), protocol)
conn._socket = MagicMock()
await conn._connect_init_frame_helper() await conn._connect_init_frame_helper()
loop.call_soon(conn._frame_helper._ready_future.set_result, None)
conn._connection_state = ConnectionState.CONNECTED conn._connection_state = ConnectionState.CONNECTED
with pytest.raises(RequiresEncryptionAPIError): with pytest.raises(RequiresEncryptionAPIError):