Skip to content

Commit

Permalink
make hound happy again
Browse files Browse the repository at this point in the history
  • Loading branch information
rytilahti committed Oct 21, 2017
1 parent 3f6ed45 commit d7d8e52
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 31 deletions.
37 changes: 21 additions & 16 deletions miio/tests/test_plug.py
Expand Up @@ -3,6 +3,7 @@
from .dummies import DummyDevice
import pytest


class DummyPlug(DummyDevice, Plug):
def __init__(self, *args, **kwargs):
self.state = {
Expand All @@ -16,41 +17,45 @@ def __init__(self, *args, **kwargs):
}
super().__init__(args, kwargs)


@pytest.fixture(scope="class")
def plug(request):
request.cls.device = DummyPlug()
# TODO add ability to test on a real device

@pytest.mark.usefixtures("plug")

@pytest.mark.usefixtures("plug")
class TestPlug(TestCase):
def is_on(self):
return self.device.status().is_on

def state(self):
return self.device.status()

def test_on(self):
self.device.off() # ensure off
is_on = lambda: self.device.status().is_on
start_state = is_on()
assert start_state == False

self.device.on()
assert is_on() == True
start_state = self.is_on()
assert start_state is False

self.device.on()
assert self.is_on() is True

def test_off(self):
self.device.on() # ensure on
is_on = lambda: self.device.status().is_on
assert is_on() == True

assert self.is_on() is True
self.device.off()
assert is_on() == False
assert self.is_on() is False

def test_status(self):
self.device._reset_state()
state = lambda: self.device.status()
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

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

def test_status_without_current(self):
del self.device.state["current"]
state = lambda: self.device.status()
assert state().load_power is None

assert self.state().load_power is None
40 changes: 25 additions & 15 deletions miio/tests/test_yeelight.py
Expand Up @@ -4,6 +4,7 @@
import pytest
from .dummies import DummyDevice


class DummyLight(DummyDevice, Yeelight):
def __init__(self, *args, **kwargs):
self.state = {
Expand Down Expand Up @@ -55,37 +56,39 @@ def dummylight(request):
request.cls.device = DummyLight()
# TODO add ability to test on a real device


@pytest.mark.usefixtures("dummylight")
class TestYeelight(TestCase):
def test_status(self):
self.device._reset_state()
status = self.device.status() # type: YeelightStatus
assert status.name == self.device.start_state["name"]
assert status.is_on == False
assert status.is_on is False
assert status.brightness == 100
assert status.color_temp == 3584
assert status.color_mode == YeelightMode.ColorTemperature
assert status.developer_mode == True
assert status.save_state_on_change == True
assert status.developer_mode is True
assert status.save_state_on_change is True

# following are tested in set mode tests
# assert status.rgb == 16711680
# assert status.hsv == (359, 100, 100)

def test_on(self):
self.device.off() # make sure we are off
assert self.device.status().is_on == False
self.device.off() # make sure we are off
assert self.device.status().is_on is False
self.device.on()
assert self.device.status().is_on == True
assert self.device.status().is_on is True

def test_off(self):
self.device.on() # make sure we are on
assert self.device.status().is_on == True
self.device.on() # make sure we are on
assert self.device.status().is_on is True
self.device.off()
assert self.device.status().is_on == False
assert self.device.status().is_on is False

def test_set_brightness(self):
brightness = lambda: self.device.status().brightness
def brightness():
return self.device.status().brightness

self.device.set_brightness(50)
assert brightness() == 50
Expand All @@ -100,7 +103,9 @@ def test_set_brightness(self):
self.device.set_brightness(200)

def test_set_color_temp(self):
color_temp = lambda: self.device.status().color_temp
def color_temp():
return self.device.status().color_temp

self.device.set_color_temp(2000)
assert color_temp() == 2000
self.device.set_color_temp(6500)
Expand Down Expand Up @@ -132,7 +137,8 @@ def test_set_hsv(self):
self.device.set_hsv()

def test_set_developer_mode(self):
dev_mode = lambda: self.device.status().developer_mode
def dev_mode():
return self.device.status().developer_mode

orig_mode = dev_mode()
self.device.set_developer_mode(not orig_mode)
Expand All @@ -142,7 +148,9 @@ def test_set_developer_mode(self):
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
def save_state():
return self.device.status().save_state_on_change

orig_state = save_state()
self.device.set_save_state_on_change(not orig_state)
new_state = save_state()
Expand All @@ -152,14 +160,16 @@ def test_set_save_state_on_change(self):
assert new_state is orig_state

def test_set_name(self):
name = lambda: self.device.status().name
def name():
return self.device.status().name

assert name() == "test name"
self.device.set_name("new test name")
assert name() == "new test name"

def test_toggle(self):
is_on = lambda: self.device.status().is_on
def is_on():
return self.device.status().is_on

orig_state = is_on()
self.device.toggle()
Expand Down

0 comments on commit d7d8e52

Please sign in to comment.