-
-
Notifications
You must be signed in to change notification settings - Fork 566
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 a base to allow easier testing of devices #99
Conversation
To demonstrate its functionality unittests for yeelight and plug are included in this commit. It also allowed to spot a couple of bugs in yeelight already..
miio/tests/test_yeelight.py
Outdated
assert name() == "new test name" | ||
|
||
def test_toggle(self): | ||
is_on = lambda: self.device.status().is_on |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do not assign a lambda expression, use a def
miio/tests/test_yeelight.py
Outdated
assert new_state is orig_state | ||
|
||
def test_set_name(self): | ||
name = lambda: self.device.status().name |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do not assign a lambda expression, use a def
miio/tests/test_yeelight.py
Outdated
assert new_mode is not dev_mode() | ||
|
||
def test_set_save_state_on_change(self): | ||
save_state = lambda: self.device.status().save_state_on_change |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do not assign a lambda expression, use a def
miio/tests/test_yeelight.py
Outdated
self.device.set_hsv() | ||
|
||
def test_set_developer_mode(self): | ||
dev_mode = lambda: self.device.status().developer_mode |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do not assign a lambda expression, use a def
miio/tests/test_yeelight.py
Outdated
self.device.set_brightness(200) | ||
|
||
def test_set_color_temp(self): | ||
color_temp = lambda: self.device.status().color_temp |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do not assign a lambda expression, use a def
miio/tests/test_yeelight.py
Outdated
# assert status.hsv == (359, 100, 100) | ||
|
||
def test_on(self): | ||
self.device.off() # make sure we are off |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
at least two spaces before inline comment
miio/tests/test_yeelight.py
Outdated
assert status.color_temp == 3584 | ||
assert status.color_mode == YeelightMode.ColorTemperature | ||
assert status.developer_mode == True | ||
assert status.save_state_on_change == True |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
comparison to True should be 'if cond is True:' or 'if cond:'
miio/tests/test_yeelight.py
Outdated
assert status.brightness == 100 | ||
assert status.color_temp == 3584 | ||
assert status.color_mode == YeelightMode.ColorTemperature | ||
assert status.developer_mode == True |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
comparison to True should be 'if cond is True:' or 'if cond:'
miio/tests/test_yeelight.py
Outdated
self.device._reset_state() | ||
status = self.device.status() # type: YeelightStatus | ||
assert status.name == self.device.start_state["name"] | ||
assert status.is_on == False |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
comparison to False should be 'if cond is False:' or 'if not cond:'
miio/tests/test_yeelight.py
Outdated
request.cls.device = DummyLight() | ||
# TODO add ability to test on a real device | ||
|
||
@pytest.mark.usefixtures("dummylight") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
expected 2 blank lines, found 1
miio/tests/test_yeelight.py
Outdated
import pytest | ||
from .dummies import DummyDevice | ||
|
||
class DummyLight(DummyDevice, Yeelight): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
expected 2 blank lines, found 1
@@ -0,0 +1,188 @@ | |||
from unittest import TestCase | |||
from miio import Yeelight | |||
from miio.yeelight import YeelightMode, YeelightStatus, YeelightException |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
'miio.yeelight.YeelightStatus' imported but unused
miio/tests/test_plug.py
Outdated
|
||
def test_status_without_current(self): | ||
del self.device.state["current"] | ||
state = lambda: self.device.status() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do not assign a lambda expression, use a def
miio/tests/test_plug.py
Outdated
print(state()) | ||
assert state().is_on == True | ||
assert state().temperature == self.device.start_state["temperature"] | ||
assert state().load_power == self.device.start_state["current"] * 110 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
multiple spaces after operator
miio/tests/test_plug.py
Outdated
self.device._reset_state() | ||
state = lambda: self.device.status() | ||
print(state()) | ||
assert state().is_on == True |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
comparison to True should be 'if cond is True:' or 'if cond:'
miio/tests/test_plug.py
Outdated
self.device.off() # ensure off | ||
is_on = lambda: self.device.status().is_on | ||
start_state = is_on() | ||
assert start_state == False |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
comparison to False should be 'if cond is False:' or 'if not cond:'
miio/tests/test_plug.py
Outdated
class TestPlug(TestCase): | ||
def test_on(self): | ||
self.device.off() # ensure off | ||
is_on = lambda: self.device.status().is_on |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do not assign a lambda expression, use a def
miio/tests/test_plug.py
Outdated
|
||
@pytest.mark.usefixtures("plug") | ||
|
||
class TestPlug(TestCase): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
blank lines found after function decorator
miio/tests/test_plug.py
Outdated
request.cls.device = DummyPlug() | ||
# TODO add ability to test on a real device | ||
|
||
@pytest.mark.usefixtures("plug") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
expected 2 blank lines, found 1
miio/tests/test_plug.py
Outdated
} | ||
super().__init__(args, kwargs) | ||
|
||
@pytest.fixture(scope="class") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
expected 2 blank lines, found 1
6dfd144
to
9e97677
Compare
miio/tests/test_plug.py
Outdated
|
||
def test_status_without_current(self): | ||
del self.device.state["current"] | ||
def state(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
expected 1 blank line before a nested definition, found 0
miio/tests/test_plug.py
Outdated
|
||
assert state().is_on is True | ||
assert state().temperature == self.device.start_state["temperature"] | ||
assert state().load_power == self.device.start_state["current"] * 110 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
multiple spaces after operator
miio/tests/test_plug.py
Outdated
|
||
def test_off(self): | ||
self.device.on() # ensure on | ||
def is_on(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
expected 1 blank line before a nested definition, found 0
miio/tests/test_plug.py
Outdated
assert is_on() is True | ||
|
||
|
||
def test_off(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
too many blank lines (2)
miio/tests/test_plug.py
Outdated
class TestPlug(TestCase): | ||
def test_on(self): | ||
self.device.off() # ensure off | ||
def is_on(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
expected 1 blank line before a nested definition, found 0
miio/tests/test_plug.py
Outdated
from .dummies import DummyDevice | ||
import pytest | ||
|
||
class DummyPlug(DummyDevice, Plug): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
expected 2 blank lines, found 1
miio/tests/test_plug.py
Outdated
|
||
def test_status_without_current(self): | ||
del self.device.state["current"] | ||
def state(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
expected 1 blank line before a nested definition, found 0
miio/tests/test_plug.py
Outdated
|
||
assert state().is_on is True | ||
assert state().temperature == self.device.start_state["temperature"] | ||
assert state().load_power == self.device.start_state["current"] * 110 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
multiple spaces after operator
miio/tests/test_plug.py
Outdated
|
||
def test_off(self): | ||
self.device.on() # ensure on | ||
def is_on(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
expected 1 blank line before a nested definition, found 0
miio/tests/test_plug.py
Outdated
assert is_on() is True | ||
|
||
|
||
def test_off(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
too many blank lines (2)
miio/tests/test_plug.py
Outdated
class TestPlug(TestCase): | ||
def test_on(self): | ||
self.device.off() # ensure off | ||
def is_on(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
expected 1 blank line before a nested definition, found 0
miio/tests/test_plug.py
Outdated
from .dummies import DummyDevice | ||
import pytest | ||
|
||
class DummyPlug(DummyDevice, Plug): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
expected 2 blank lines, found 1
9e97677
to
d7d8e52
Compare
|
||
assert self.is_on() is True | ||
assert self.state().temperature == self.device.start_state["temperature"] | ||
assert self.state().load_power == self.device.start_state["current"] * 110 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
line too long (82 > 79 characters)
self.device._reset_state() | ||
|
||
assert self.is_on() is True | ||
assert self.state().temperature == self.device.start_state["temperature"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
line too long (81 > 79 characters)
Cool! Could be merged. I will try to adopt the test for a air purifier soon! |
To demonstrate its functionality unittests for yeelight and plug
are included in this commit. It also allowed to spot a couple of bugs
in yeelight already..