Skip to content

Commit

Permalink
introduce black formatter
Browse files Browse the repository at this point in the history
  • Loading branch information
no2chem committed Nov 21, 2020
1 parent 6e4f9d6 commit fb3c755
Show file tree
Hide file tree
Showing 18 changed files with 807 additions and 695 deletions.
5 changes: 5 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[flake8]
ignore = E203, E266, E501, W503, F403, F401
max-line-length = 79
max-complexity = 18
select = B,C,E,F,W,T4,B9
10 changes: 10 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
repos:
- repo: https://github.com/ambv/black
rev: stable
hooks:
- id: black
language_version: python3.9
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v1.2.3
hooks:
- id: flake8
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ You can also specify one of several other commands:
* `turn <ID> <ONOFF>`: Turn an AC device on or off. Use "on" or "off" as the second argument.
* `ac-config <ID>`: Print out some configuration information about an AC device.

Development
-------
To ensure consistent formatting across pull requests, install the precommit hooks to auto format your code using `pre-commit install`.

The code will be auto-formatted by `black` to ensure consistent style.

Credits
-------
Expand Down
18 changes: 17 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[build-system]
requires = ["flit"]
requires = ["flit", "pre-commit"]
build-backend = "flit.buildapi"

[tool.flit.metadata]
Expand All @@ -16,3 +16,19 @@ requires-python = ">=3.6"
test = [
"responses"
]

[tool.black]
line-length = 79
include = '\.pyi?$'
exclude = '''
/(
\.git
| \.hg
| \.mypy_cache
| \.tox
| \.venv
| _build
| build
| dist
)/
'''
181 changes: 92 additions & 89 deletions tests/test_client.py
Original file line number Diff line number Diff line change
@@ -1,148 +1,151 @@
import unittest

from wideq.client import (
BitValue, EnumValue, ModelInfo, RangeValue, ReferenceValue, StringValue)
BitValue,
EnumValue,
ModelInfo,
RangeValue,
ReferenceValue,
StringValue,
)


DATA = {
'Value': {
'AntiBacterial': {
'default': '0',
'label': '@WM_DRY27_BUTTON_ANTI_BACTERIAL_W',
'option': {
'0': '@CP_OFF_EN_W',
'1': '@CP_ON_EN_W'
},
'type': 'Enum'
"Value": {
"AntiBacterial": {
"default": "0",
"label": "@WM_DRY27_BUTTON_ANTI_BACTERIAL_W",
"option": {"0": "@CP_OFF_EN_W", "1": "@CP_ON_EN_W"},
"type": "Enum",
},
'Course': {
'option': ['Course'],
'type': 'Reference',
"Course": {
"option": ["Course"],
"type": "Reference",
},
'Initial_Time_H': {
'default': 0,
'option': {'max': 24, 'min': 0},
'type': 'Range'
"Initial_Time_H": {
"default": 0,
"option": {"max": 24, "min": 0},
"type": "Range",
},
'Option1': {
'default': '0',
'option': [
"Option1": {
"default": "0",
"option": [
{
'default': '0',
'length': 1,
'startbit': 0,
'value': 'ChildLock'
"default": "0",
"length": 1,
"startbit": 0,
"value": "ChildLock",
},
{
'default': '0',
'length': 1,
'startbit': 1,
'value': 'ReduceStatic'
"default": "0",
"length": 1,
"startbit": 1,
"value": "ReduceStatic",
},
{
'default': '0',
'length': 1,
'startbit': 2,
'value': 'EasyIron'
"default": "0",
"length": 1,
"startbit": 2,
"value": "EasyIron",
},
{
'default': '0',
'length': 1,
'startbit': 3,
'value': 'DampDrySingal'
"default": "0",
"length": 1,
"startbit": 3,
"value": "DampDrySingal",
},
{
'default': '0',
'length': 1,
'startbit': 4,
'value': 'WrinkleCare'
"default": "0",
"length": 1,
"startbit": 4,
"value": "WrinkleCare",
},
{
'default': '0',
'length': 1,
'startbit': 7,
'value': 'AntiBacterial'
}
"default": "0",
"length": 1,
"startbit": 7,
"value": "AntiBacterial",
},
],
'type': 'Bit'
},
'TimeBsOn': {
'_comment':
'오전 12시 30분은 0030, 오후12시30분은 1230 ,오후 4시30분은 1630 off는 0 ',
'type': 'String'
"type": "Bit",
},
'Unexpected': {'type': 'Unexpected'},
'Unexpected2': {
'type': 'Unexpected',
'option': 'some option'
"TimeBsOn": {
"_comment": "오전 12시 30분은 0030, 오후12시30분은 1230 ,오후 4시30분은 1630 off는 0 ",
"type": "String",
},
"Unexpected": {"type": "Unexpected"},
"Unexpected2": {"type": "Unexpected", "option": "some option"},
},
'Course': {
"Course": {
"3": {
"_comment": "Normal",
"courseType": "Course",
"id": 3,
"name": "@WM_DRY27_COURSE_NORMAL_W",
"script": "",
"controlEnable": True,
"freshcareEnable": True,
"imgIndex": 61,
"_comment": "Normal",
"courseType": "Course",
"id": 3,
"name": "@WM_DRY27_COURSE_NORMAL_W",
"script": "",
"controlEnable": True,
"freshcareEnable": True,
"imgIndex": 61,
},
},
}


class ModelInfoTest(unittest.TestCase):

def setUp(self):
super().setUp()
self.model_info = ModelInfo(DATA)

def test_value_enum(self):
actual = self.model_info.value('AntiBacterial')
expected = EnumValue({'0': '@CP_OFF_EN_W', '1': '@CP_ON_EN_W'})
actual = self.model_info.value("AntiBacterial")
expected = EnumValue({"0": "@CP_OFF_EN_W", "1": "@CP_ON_EN_W"})
self.assertEqual(expected, actual)

def test_value_range(self):
actual = self.model_info.value('Initial_Time_H')
actual = self.model_info.value("Initial_Time_H")
expected = RangeValue(min=0, max=24, step=1)
self.assertEqual(expected, actual)

def test_value_bit(self):
actual = self.model_info.value('Option1')
expected = BitValue({
0: 'ChildLock',
1: 'ReduceStatic',
2: 'EasyIron',
3: 'DampDrySingal',
4: 'WrinkleCare',
7: 'AntiBacterial',
})
actual = self.model_info.value("Option1")
expected = BitValue(
{
0: "ChildLock",
1: "ReduceStatic",
2: "EasyIron",
3: "DampDrySingal",
4: "WrinkleCare",
7: "AntiBacterial",
}
)
self.assertEqual(expected, actual)

def test_value_reference(self):
actual = self.model_info.value('Course')
expected = ReferenceValue(DATA['Course'])
actual = self.model_info.value("Course")
expected = ReferenceValue(DATA["Course"])
self.assertEqual(expected, actual)

def test_string(self):
actual = self.model_info.value('TimeBsOn')
actual = self.model_info.value("TimeBsOn")
expected = StringValue(
"오전 12시 30분은 0030, 오후12시30분은 1230 ,오후 4시30분은 1630 off는 0 ")
"오전 12시 30분은 0030, 오후12시30분은 1230 ,오후 4시30분은 1630 off는 0 "
)
self.assertEqual(expected, actual)

def test_value_unsupported(self):
data = "{'type': 'Unexpected'}"
with self.assertRaisesRegex(
ValueError,
f"unsupported value name: 'Unexpected' type: 'Unexpected' "
f"data: '{data}'"):
self.model_info.value('Unexpected')
ValueError,
f"unsupported value name: 'Unexpected' type: 'Unexpected' "
f"data: '{data}'",
):
self.model_info.value("Unexpected")

def test_value_unsupported_but_data_available(self):
data = "{'type': 'Unexpected', 'option': 'some option'}"
with self.assertRaisesRegex(
ValueError,
f"unsupported value name: 'Unexpected2'"
f" type: 'Unexpected' data: '{data}"):
self.model_info.value('Unexpected2')
ValueError,
f"unsupported value name: 'Unexpected2'"
f" type: 'Unexpected' data: '{data}",
):
self.model_info.value("Unexpected2")
57 changes: 31 additions & 26 deletions tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,47 +9,52 @@ class SimpleTest(unittest.TestCase):
def test_gateway_en_US(self):
responses.add(
responses.POST,
'https://kic.lgthinq.com:46030/api/common/gatewayUriList',
"https://kic.lgthinq.com:46030/api/common/gatewayUriList",
json={
'lgedmRoot': {
"lgedmRoot": {
"thinqUri": "https://aic.lgthinq.com:46030/api",
"empUri": "https://us.m.lgaccount.com",
"oauthUri": "https://us.lgeapi.com",
"countryCode": "US",
"langCode": "en-US",
}
}
},
)
gatewayInstance = wideq.core.Gateway.discover('US', 'en-US')
gatewayInstance = wideq.core.Gateway.discover("US", "en-US")
self.assertEqual(len(responses.calls), 1)
self.assertEqual(gatewayInstance.country, 'US')
self.assertEqual(gatewayInstance.language, 'en-US')
self.assertEqual(gatewayInstance.auth_base,
'https://us.m.lgaccount.com')
self.assertEqual(gatewayInstance.api_root,
'https://aic.lgthinq.com:46030/api')
self.assertEqual(gatewayInstance.oauth_root, 'https://us.lgeapi.com')
self.assertEqual(gatewayInstance.country, "US")
self.assertEqual(gatewayInstance.language, "en-US")
self.assertEqual(
gatewayInstance.auth_base, "https://us.m.lgaccount.com"
)
self.assertEqual(
gatewayInstance.api_root, "https://aic.lgthinq.com:46030/api"
)
self.assertEqual(gatewayInstance.oauth_root, "https://us.lgeapi.com")

@responses.activate
def test_gateway_en_NO(self):
responses.add(
responses.POST,
'https://kic.lgthinq.com:46030/api/common/gatewayUriList',
"https://kic.lgthinq.com:46030/api/common/gatewayUriList",
json={
'lgedmRoot': {
"countryCode": "NO", "langCode": "en-NO",
"thinqUri": "https://eic.lgthinq.com:46030/api",
"empUri": "https://no.m.lgaccount.com",
"oauthUri": "https://no.lgeapi.com",
"lgedmRoot": {
"countryCode": "NO",
"langCode": "en-NO",
"thinqUri": "https://eic.lgthinq.com:46030/api",
"empUri": "https://no.m.lgaccount.com",
"oauthUri": "https://no.lgeapi.com",
}
}
},
)
gatewayInstance = wideq.core.Gateway.discover('NO', 'en-NO')
gatewayInstance = wideq.core.Gateway.discover("NO", "en-NO")
self.assertEqual(len(responses.calls), 1)
self.assertEqual(gatewayInstance.country, 'NO')
self.assertEqual(gatewayInstance.language, 'en-NO')
self.assertEqual(gatewayInstance.auth_base,
'https://no.m.lgaccount.com')
self.assertEqual(gatewayInstance.api_root,
'https://eic.lgthinq.com:46030/api')
self.assertEqual(gatewayInstance.oauth_root, 'https://no.lgeapi.com')
self.assertEqual(gatewayInstance.country, "NO")
self.assertEqual(gatewayInstance.language, "en-NO")
self.assertEqual(
gatewayInstance.auth_base, "https://no.m.lgaccount.com"
)
self.assertEqual(
gatewayInstance.api_root, "https://eic.lgthinq.com:46030/api"
)
self.assertEqual(gatewayInstance.oauth_root, "https://no.lgeapi.com")
Loading

0 comments on commit fb3c755

Please sign in to comment.