Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add azure pipeline for tests, and enforce black, flake8 and isort for commits #566

Merged
merged 7 commits into from
Oct 27, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions .flake8.ini

This file was deleted.

16 changes: 16 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,19 @@ repos:
hooks:
- id: black
language_version: python3

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.3.0
hooks:
- id: flake8

- repo: https://github.com/pre-commit/mirrors-isort
rev: v4.3.21
hooks:
- id: isort

#- repo: https://github.com/pre-commit/mirrors-mypy
# rev: v0.740
# hooks:
# - id: mypy
# args: [--no-strict-optional, --ignore-missing-imports]
48 changes: 48 additions & 0 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
trigger:
- master
pr:
- master

pool:
vmImage: 'ubuntu-latest'
strategy:
matrix:
Python36:
python.version: '3.6'
Python37:
python.version: '3.7'
# Python38:
# python.version: '3.8'

steps:
- task: UsePythonVersion@0
inputs:
versionSpec: '$(python.version)'
displayName: 'Use Python $(python.version)'

- script: |
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install pytest pytest-azurepipelines
pre-commit install-hooks
displayName: 'Install dependencies'

- script: |
pre-commit run black --all-files
displayName: 'Code formating (black)'

- script: |
pre-commit run flake8 --all-files
displayName: 'Code formating (flake8)'

- script: |
pre-commit run mypy --all-files
displayName: 'Typing checks (mypy)'

- script: |
pre-commit run isort --all-files
displayName: 'Order of imports (isort)'

- script: |
pytest
displayName: 'Tests'
27 changes: 14 additions & 13 deletions miio/__init__.py
Original file line number Diff line number Diff line change
@@ -1,38 +1,39 @@
# flake8: noqa
from miio.airconditioningcompanion import AirConditioningCompanion
from miio.airconditioningcompanion import AirConditioningCompanionV3
from miio.airconditioningcompanion import (
AirConditioningCompanion,
AirConditioningCompanionV3,
)
from miio.airdehumidifier import AirDehumidifier
from miio.airfresh import AirFresh
from miio.airhumidifier import AirHumidifier
from miio.airdehumidifier import AirDehumidifier
from miio.airpurifier import AirPurifier
from miio.airqualitymonitor import AirQualityMonitor
from miio.aqaracamera import AqaraCamera
from miio.ceil import Ceil
from miio.chuangmi_camera import ChuangmiCamera
from miio.chuangmi_ir import ChuangmiIr
from miio.chuangmi_plug import Plug, PlugV1, PlugV3, ChuangmiPlug
from miio.chuangmi_plug import ChuangmiPlug, Plug, PlugV1, PlugV3
from miio.cooker import Cooker
from miio.device import Device, DeviceException, DeviceError
from miio.fan import Fan, FanV2, FanSA1, FanZA1, FanZA4, FanP5
from miio.device import Device, DeviceError, DeviceException
from miio.discovery import Discovery
from miio.fan import Fan, FanP5, FanSA1, FanV2, FanZA1, FanZA4
from miio.philips_bulb import PhilipsBulb
from miio.philips_eyecare import PhilipsEyecare
from miio.philips_moonlight import PhilipsMoonlight
from miio.powerstrip import PowerStrip
from miio.protocol import Message, Utils
from miio.toiletlid import Toiletlid
from miio.pwzn_relay import PwznRelay
from miio.toiletlid import Toiletlid
from miio.vacuum import Vacuum, VacuumException
from miio.vacuumcontainers import (
VacuumStatus,
ConsumableStatus,
DNDStatus,
CleaningDetails,
CleaningSummary,
ConsumableStatus,
DNDStatus,
Timer,
VacuumStatus,
)
from miio.waterpurifier import WaterPurifier
from miio.wifirepeater import WifiRepeater
from miio.wifispeaker import WifiSpeaker
from miio.yeelight import Yeelight
from miio.aqaracamera import AqaraCamera

from miio.discovery import Discovery
2 changes: 1 addition & 1 deletion miio/airconditioningcompanion.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import click

from .click_common import command, format_output, EnumType
from .click_common import EnumType, command, format_output
from .device import Device, DeviceException

_LOGGER = logging.getLogger(__name__)
Expand Down
4 changes: 2 additions & 2 deletions miio/airdehumidifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

import click

from .click_common import command, format_output, EnumType
from .device import Device, DeviceInfo, DeviceError, DeviceException
from .click_common import EnumType, command, format_output
from .device import Device, DeviceError, DeviceException, DeviceInfo

_LOGGER = logging.getLogger(__name__)

Expand Down
2 changes: 1 addition & 1 deletion miio/airfresh.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import click

from .click_common import command, format_output, EnumType
from .click_common import EnumType, command, format_output
from .device import Device, DeviceException

_LOGGER = logging.getLogger(__name__)
Expand Down
4 changes: 2 additions & 2 deletions miio/airhumidifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

import click

from .click_common import command, format_output, EnumType
from .device import Device, DeviceInfo, DeviceError, DeviceException
from .click_common import EnumType, command, format_output
from .device import Device, DeviceError, DeviceException, DeviceInfo

_LOGGER = logging.getLogger(__name__)

Expand Down
2 changes: 1 addition & 1 deletion miio/airpurifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import click

from .click_common import command, format_output, EnumType
from .click_common import EnumType, command, format_output
from .device import Device, DeviceException

_LOGGER = logging.getLogger(__name__)
Expand Down
17 changes: 8 additions & 9 deletions miio/airqualitymonitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,7 @@
"sensor_state",
]

AVAILABLE_PROPERTIES_B1 = [
"co2e",
"humidity",
"pm25",
"temperature",
"tvoc"
]
AVAILABLE_PROPERTIES_B1 = ["co2e", "humidity", "pm25", "temperature", "tvoc"]

AVAILABLE_PROPERTIES_S1 = ["battery", "co2", "humidity", "pm25", "temperature", "tvoc"]

Expand Down Expand Up @@ -204,7 +198,9 @@ def __init__(
self.model = model
elif model is not None:
self.model = MODEL_AIRQUALITYMONITOR_V1
_LOGGER.error("Device model %s unsupported. Falling back to %s.", model, self.model)
_LOGGER.error(
"Device model %s unsupported. Falling back to %s.", model, self.model
rytilahti marked this conversation as resolved.
Show resolved Hide resolved
)
else:
"""Force autodetection"""
self.model = None
Expand Down Expand Up @@ -250,7 +246,10 @@ def status(self) -> AirQualityMonitorStatus:
values_count,
)

if self.model == MODEL_AIRQUALITYMONITOR_S1 or self.model == MODEL_AIRQUALITYMONITOR_B1:
if (
self.model == MODEL_AIRQUALITYMONITOR_S1
or self.model == MODEL_AIRQUALITYMONITOR_B1
):
return AirQualityMonitorStatus(defaultdict(lambda: None, values))
else:
return AirQualityMonitorStatus(
Expand Down
3 changes: 2 additions & 1 deletion miio/alarmclock.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import enum
import time

import click

from .click_common import EnumType, command
from .device import Device
from .click_common import command, EnumType


class HourlySystem(enum.Enum):
Expand Down
4 changes: 2 additions & 2 deletions miio/aqaracamera.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
TODO: add sdcard status & fix all TODOS
TODO: add tests
"""
import attr
import logging
from typing import Any, Dict
from enum import IntEnum
from typing import Any, Dict

import attr
import click

from .click_common import command, format_output
Expand Down
18 changes: 9 additions & 9 deletions miio/chuangmi_ir.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@

import click
from construct import (
Struct,
Const,
Rebuild,
this,
len_,
Adapter,
Array,
BitsInteger,
BitStruct,
Computed,
Const,
Int16ub,
Int16ul,
Int32ul,
Int16ub,
Array,
BitStruct,
BitsInteger,
Rebuild,
Struct,
len_,
this,
)

from .click_common import command, format_output
Expand Down
2 changes: 1 addition & 1 deletion miio/chuangmi_plug.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import logging
from collections import defaultdict
from typing import Dict, Any, Optional
from typing import Any, Dict, Optional

import click

Expand Down
2 changes: 1 addition & 1 deletion miio/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
import click

from miio.click_common import (
ExceptionHandlerGroup,
DeviceGroupMeta,
ExceptionHandlerGroup,
GlobalContextObject,
json_output,
)
Expand Down
22 changes: 12 additions & 10 deletions miio/click_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,25 @@
This file contains common functions for cli tools.
"""
import ast
import ipaddress
import json
import logging
import re
import sys
from functools import partial, wraps
from typing import Union

import click

import miio

from .exceptions import DeviceError

if sys.version_info < (3, 5):
print(
"To use this script you need python 3.5 or newer, got %s" % (sys.version_info,)
)
sys.exit(1)
import click
import ipaddress
import miio
import logging
import json
import re
from typing import Union
from functools import wraps
from functools import partial
from .exceptions import DeviceError


_LOGGER = logging.getLogger(__name__)
Expand Down
2 changes: 1 addition & 1 deletion miio/cooker.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import string
from collections import defaultdict
from datetime import time
from typing import Optional, List
from typing import List, Optional

import click

Expand Down
4 changes: 2 additions & 2 deletions miio/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
import click
import construct

from .click_common import DeviceGroupMeta, command, format_output, LiteralParamType
from .exceptions import DeviceException, DeviceError, RecoverableError
from .click_common import DeviceGroupMeta, LiteralParamType, command, format_output
rytilahti marked this conversation as resolved.
Show resolved Hide resolved
from .exceptions import DeviceError, DeviceException, RecoverableError
from .protocol import Message

_LOGGER = logging.getLogger(__name__)
Expand Down
Loading