Skip to content

Commit

Permalink
Use newer dependencies
Browse files Browse the repository at this point in the history
* Use pytest-httpx

* Fix Python 3.7

* Fix AsyncMockMixin warning

* Fix warnings

* Update httpx requirement from <0.17,>=0.14 to >=0.14,<0.18

Updates the requirements on [httpx](https://github.com/encode/httpx) to permit the latest version.
- [Release notes](https://github.com/encode/httpx/releases)
- [Changelog](https://github.com/encode/httpx/blob/master/CHANGELOG.md)
- [Commits](encode/httpx@0.14.0...0.17.0)

Signed-off-by: dependabot[bot] <support@github.com>

* use scm_version

* Update httpx requirement from <0.18,>=0.14 to >=0.14,<0.19

Updates the requirements on [httpx](https://github.com/encode/httpx) to permit the latest version.
- [Release notes](https://github.com/encode/httpx/releases)
- [Changelog](https://github.com/encode/httpx/blob/master/CHANGELOG.md)
- [Commits](encode/httpx@0.14.0...0.18.0)

Signed-off-by: dependabot[bot] <support@github.com>

* Adapt to updated pytest-httpx

* Update test requirements

* Update httpx requirement from <0.19,>=0.14 to >=0.14,<0.20 (#42)

* Update httpx requirement from <0.19,>=0.14 to >=0.14,<0.20

Updates the requirements on [httpx](https://github.com/encode/httpx) to permit the latest version.
- [Release notes](https://github.com/encode/httpx/releases)
- [Changelog](https://github.com/encode/httpx/blob/master/CHANGELOG.md)
- [Commits](encode/httpx@0.14.0...0.19.0)

---
updated-dependencies:
- dependency-name: httpx
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>

* Fix mypy

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Guido Schmitz <guido.schmitz@fedaix.de>

* Update changelog

* Add revs

* Fix pacakge name

Co-authored-by: Markus Bong <2Fake1987@gmail.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Markus Bong <Markus.Bong@devolo.de>
  • Loading branch information
4 people authored Sep 2, 2021
1 parent 9d875d1 commit 44a1af1
Show file tree
Hide file tree
Showing 17 changed files with 204 additions and 222 deletions.
1 change: 0 additions & 1 deletion .github/pull_request_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,4 @@
Put an 'x' in the boxes that apply.
-->

- [ ] Version number in \_\_init\_\_.py was properly set.
- [ ] Changelog is updated.
12 changes: 6 additions & 6 deletions .github/workflows/pythonpackage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,18 @@ jobs:
- name: Lint with flake8
run: |
python -m pip install --upgrade pip
pip install flake8
python -m pip install flake8
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
flake8 . --count --exit-zero --statistics
- name: Lint with pylint
run: |
pip install pylint
pip install -e .
python -m pip install pylint
python -m pip install -e .
pylint --errors-only --score=n devolo_plc_api
pylint --exit-zero --score=n --disable=C,E,R --enable=useless-suppression --ignore-patterns=.*_pb2.py devolo_plc_api devolo_plc_api
- name: Lint with mypy
run: |
pip install mypy
python -m pip install mypy types-protobuf
mypy devolo_plc_api
test:
Expand All @@ -60,7 +60,7 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -e .[test]
python -m pip install -e .[test]
- name: Test with pytest
run: |
pytest --cov=devolo_plc_api
Expand Down Expand Up @@ -88,7 +88,7 @@ jobs:
- name: Coveralls
run: |
python -m pip install --upgrade pip
pip install wheel coveralls
python -m pip install wheel coveralls
export COVERALLS_REPO_TOKEN=${{ secrets.COVERALLS_TOKEN }}
coveralls
- name: Clean up coverage
Expand Down
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
repos:
- repo: https://github.com/pre-commit/mirrors-yapf
rev: ''
rev: 'v0.31.0'
hooks:
- id: yapf
- repo: https://github.com/pycqa/isort
rev: ''
rev: '5.9.3'
hooks:
- id: isort
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: ''
rev: 'v4.0.1'
hooks:
- id: end-of-file-fixer
- id: trailing-whitespace
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Other versions and even other operating systems might work. Feel free to tell us
* pytest 5.4.3
* pytest-asyncio 0.14.0
* pytest-mock 3.2.0
* pytest-httpx 0.12
* asynctest 0.13.0

## Versioning
Expand Down
11 changes: 10 additions & 1 deletion devolo_plc_api/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,10 @@
__version__ = "0.5.1"
try:
from importlib.metadata import PackageNotFoundError, version
except ImportError:
from importlib_metadata import PackageNotFoundError, version # type: ignore[no-redef]

try:
__version__ = version("devolo_plc_api")
except PackageNotFoundError:
# package is not installed - e.g. pulled and run locally
__version__ = "0.0.0"
9 changes: 8 additions & 1 deletion docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,18 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [v0.5.1] - 2021/12/19
## [v0.5.2] - 2021/09/01

### Changed

- Use newer dependency versions

## [v0.5.1] - 2021/01/19

### Fixed

- React correctly on different connection errors

## [v0.5.0] - 2020/12/21

### Changed
Expand Down
9 changes: 5 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
from setuptools import find_packages, setup
from setuptools.command.develop import develop

from devolo_plc_api import __version__

with open("README.md", "r") as fh:
long_description = fh.read()

Expand All @@ -24,7 +22,7 @@ def run(self):

setup(
name="devolo_plc_api",
version=__version__,
use_scm_version=True,
author="Markus Bong, Guido Schmitz",
author_email="m.bong@famabo.de, guido.schmitz@fedaix.de",
description="devolo PLC devices in Python",
Expand All @@ -39,7 +37,8 @@ def run(self):
"Operating System :: OS Independent",
],
install_requires=[
"httpx>=0.14,<0.17",
"httpx>=0.14,<0.20",
"importlib-metadata;python_version<'3.8'",
"protobuf",
"zeroconf>=0.27.0",
],
Expand All @@ -52,8 +51,10 @@ def run(self):
"pytest",
"pytest-asyncio",
"pytest-cov",
"pytest-httpx>=0.12",
"pytest-mock",
],
},
setup_requires=["setuptools_scm"],
python_requires='>=3.7',
)
5 changes: 2 additions & 3 deletions tests/fixtures/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@


@pytest.fixture()
def mock_device(mocker, request):
def mock_device(request):
device = Device(ip=request.cls.ip)
device._info = deepcopy(request.cls.device_info)
device._loop = Mock()
Expand All @@ -24,13 +24,12 @@ def mock_device(mocker, request):
device._zeroconf = Mock()
device._zeroconf.close = lambda: None
yield device
device.disconnect()


@pytest.fixture()
def mock_service_browser(mocker):
mocker.patch("zeroconf.ServiceBrowser.__init__", MockServiceBrowser.__init__)
mocker.patch("zeroconf.ServiceBrowser.cancel", return_value=None)
mocker.patch("zeroconf.ServiceBrowser.cancel")


@pytest.fixture()
Expand Down
20 changes: 7 additions & 13 deletions tests/fixtures/device_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,20 @@
from unittest.mock import patch

import pytest
from httpx import AsyncClient, Response
from httpx import AsyncClient

from devolo_plc_api.device_api.deviceapi import DeviceApi

try:
from unittest.mock import AsyncMock
except ImportError:
from asynctest import CoroutineMock as AsyncMock


@pytest.fixture()
def device_api(request, feature):
with patch("devolo_plc_api.clients.protobuf.Protobuf._async_get", new=AsyncMock(return_value=Response)), \
patch("devolo_plc_api.clients.protobuf.Protobuf._async_post", new=AsyncMock(return_value=Response)), \
patch("asyncio.get_running_loop", asyncio.new_event_loop):
asyncio.new_event_loop()
async def device_api(request, feature):
with patch("asyncio.get_running_loop", asyncio.new_event_loop):
request.cls.device_info["_dvl-deviceapi._tcp.local."]["properties"]["Features"] = feature
yield DeviceApi(request.cls.ip, AsyncClient(), request.cls.device_info["_dvl-deviceapi._tcp.local."])
async with AsyncClient() as client:
device_api = DeviceApi(request.cls.ip, client, request.cls.device_info["_dvl-deviceapi._tcp.local."])
yield device_api


@pytest.fixture()
def mock_device_api(mocker):
mocker.patch("devolo_plc_api.device_api.deviceapi.DeviceApi.__init__", return_value=None)
mocker.patch("devolo_plc_api.device_api.deviceapi.DeviceApi")
19 changes: 7 additions & 12 deletions tests/fixtures/plcnet_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,20 @@
from unittest.mock import patch

import pytest
from httpx import AsyncClient, Response
from httpx import AsyncClient

from devolo_plc_api.plcnet_api.plcnetapi import PlcNetApi

try:
from unittest.mock import AsyncMock
except ImportError:
from asynctest import CoroutineMock as AsyncMock


@pytest.fixture()
def plcnet_api(request):
with patch("devolo_plc_api.clients.protobuf.Protobuf._async_get", new=AsyncMock(return_value=Response)), \
patch("devolo_plc_api.clients.protobuf.Protobuf._async_post", new=AsyncMock(return_value=Response)), \
patch("asyncio.get_running_loop", asyncio.new_event_loop):
async def plcnet_api(request):
with patch("asyncio.get_running_loop", asyncio.new_event_loop):
asyncio.new_event_loop()
yield PlcNetApi(request.cls.ip, AsyncClient(), request.cls.device_info["_dvl-plcnetapi._tcp.local."])
async with AsyncClient() as client:
plcnet_api = PlcNetApi(request.cls.ip, client, request.cls.device_info["_dvl-plcnetapi._tcp.local."])
yield plcnet_api


@pytest.fixture()
def mock_plcnet_api(mocker):
mocker.patch("devolo_plc_api.plcnet_api.plcnetapi.PlcNetApi.__init__", return_value=None)
mocker.patch("devolo_plc_api.plcnet_api.plcnetapi.PlcNetApi")
31 changes: 12 additions & 19 deletions tests/fixtures/protobuf.py
Original file line number Diff line number Diff line change
@@ -1,36 +1,29 @@
import pytest
from httpx import ConnectTimeout

try:
from unittest.mock import AsyncMock
except ImportError:
from asynctest import CoroutineMock as AsyncMock

from ..stubs.protobuf import StubProtobuf


@pytest.fixture()
def mock_protobuf():
return StubProtobuf()
async def mock_protobuf():
protobuf = StubProtobuf()
yield protobuf
await protobuf._session.aclose()


@pytest.fixture()
def mock_get(mocker):
mocker.patch("httpx.AsyncClient.get", new=AsyncMock())
def mock_device_unavailable(httpx_mock):

def raise_type_error(request, extensions):
raise ConnectTimeout(request=request, message=extensions)

@pytest.fixture()
def mock_post(mocker):
mocker.patch("httpx.AsyncClient.post", new=AsyncMock())
httpx_mock.add_callback(raise_type_error)


@pytest.fixture()
def mock_device_unavailable(mocker):
mocker.patch("httpx.AsyncClient.get", side_effect=ConnectTimeout(message="", request=""))
mocker.patch("httpx.AsyncClient.post", side_effect=ConnectTimeout(message="", request=""))
def mock_wrong_password(httpx_mock):

def raise_type_error(request, extensions):
raise TypeError

@pytest.fixture()
def mock_wrong_password(mocker):
mocker.patch("httpx.AsyncClient.get", side_effect=TypeError())
mocker.patch("httpx.AsyncClient.post", side_effect=TypeError())
httpx_mock.add_callback(raise_type_error)
3 changes: 3 additions & 0 deletions tests/stubs/protobuf.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import logging
import pathlib

from httpx import AsyncClient

from devolo_plc_api.clients.protobuf import Protobuf

file = pathlib.Path(__file__).parent / "../test_data.json"
Expand All @@ -17,6 +19,7 @@ def __init__(self):
self._loop = asyncio.new_event_loop()
self._ip = test_data["ip"]
self._port = 14791
self._session = AsyncClient()
self._path = test_data["device_info"]["_dvl-plcnetapi._tcp.local."]["properties"]["Path"]
self._version = test_data["device_info"]["_dvl-plcnetapi._tcp.local."]["properties"]["Version"]
self._user = "user"
Expand Down
4 changes: 2 additions & 2 deletions tests/test_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ async def test__get_device_info(self, mock_device):
@pytest.mark.asyncio
@pytest.mark.usefixtures("mock_device_api")
async def test__get_device_info_timeout(self, mock_device):
with patch("devolo_plc_api.device.Device._get_zeroconf_info", new=AsyncMock()), \
with patch("devolo_plc_api.device.Device._get_zeroconf_info", new=Mock()), \
patch("asyncio.wait_for", new=AsyncMock(side_effect=asyncio.TimeoutError())):
await mock_device._get_device_info()
assert mock_device.device is None
Expand All @@ -102,7 +102,7 @@ async def test__get_plcnet_info(self, mock_device):
@pytest.mark.asyncio
@pytest.mark.usefixtures("mock_plcnet_api")
async def test__get_plcnet_info_timeout(self, mock_device):
with patch("devolo_plc_api.device.Device._get_zeroconf_info", new=AsyncMock()), \
with patch("devolo_plc_api.device.Device._get_zeroconf_info", new=Mock()), \
patch("asyncio.wait_for", new=AsyncMock(side_effect=asyncio.TimeoutError())):
await mock_device._get_plcnet_info()
assert mock_device.plcnet is None
Expand Down
Loading

0 comments on commit 44a1af1

Please sign in to comment.