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 a base to allow easier testing of devices #99

Merged
merged 2 commits into from
Oct 23, 2017
Merged

Conversation

rytilahti
Copy link
Owner

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..

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..
assert name() == "new test name"

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

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

assert new_state is orig_state

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

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

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

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

self.device.set_hsv()

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

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

self.device.set_brightness(200)

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

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

# assert status.hsv == (359, 100, 100)

def test_on(self):
self.device.off() # make sure we are off

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

assert status.color_temp == 3584
assert status.color_mode == YeelightMode.ColorTemperature
assert status.developer_mode == True
assert status.save_state_on_change == True

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:'

assert status.brightness == 100
assert status.color_temp == 3584
assert status.color_mode == YeelightMode.ColorTemperature
assert status.developer_mode == True

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:'

self.device._reset_state()
status = self.device.status() # type: YeelightStatus
assert status.name == self.device.start_state["name"]
assert status.is_on == False

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:'

request.cls.device = DummyLight()
# TODO add ability to test on a real device

@pytest.mark.usefixtures("dummylight")

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

@coveralls
Copy link

coveralls commented Oct 21, 2017

Coverage Status

Coverage increased (+5.8%) to 39.793% when pulling 3f6ed45 on add_unittest_base into ec71776 on master.

import pytest
from .dummies import DummyDevice

class DummyLight(DummyDevice, Yeelight):

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

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


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

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

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

multiple spaces after operator

self.device._reset_state()
state = lambda: self.device.status()
print(state())
assert state().is_on == True

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:'

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

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:'

class TestPlug(TestCase):
def test_on(self):
self.device.off() # ensure off
is_on = lambda: self.device.status().is_on

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


@pytest.mark.usefixtures("plug")

class TestPlug(TestCase):

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

request.cls.device = DummyPlug()
# TODO add ability to test on a real device

@pytest.mark.usefixtures("plug")

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

}
super().__init__(args, kwargs)

@pytest.fixture(scope="class")

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

@coveralls
Copy link

coveralls commented Oct 21, 2017

Coverage Status

Coverage increased (+5.6%) to 39.604% when pulling 6dfd144 on add_unittest_base into ec71776 on master.


def test_status_without_current(self):
del self.device.state["current"]
def state():

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


assert state().is_on is True
assert state().temperature == self.device.start_state["temperature"]
assert state().load_power == self.device.start_state["current"] * 110

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

multiple spaces after operator


def test_off(self):
self.device.on() # ensure on
def is_on():

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

assert is_on() is True


def test_off(self):

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)

class TestPlug(TestCase):
def test_on(self):
self.device.off() # ensure off
def is_on():

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

from .dummies import DummyDevice
import pytest

class DummyPlug(DummyDevice, Plug):

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


def test_status_without_current(self):
del self.device.state["current"]
def state():

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


assert state().is_on is True
assert state().temperature == self.device.start_state["temperature"]
assert state().load_power == self.device.start_state["current"] * 110

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

multiple spaces after operator


def test_off(self):
self.device.on() # ensure on
def is_on():

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

assert is_on() is True


def test_off(self):

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)

class TestPlug(TestCase):
def test_on(self):
self.device.off() # ensure off
def is_on():

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

from .dummies import DummyDevice
import pytest

class DummyPlug(DummyDevice, Plug):

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


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

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"]

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)

@coveralls
Copy link

coveralls commented Oct 21, 2017

Coverage Status

Coverage increased (+5.6%) to 39.596% when pulling 9e97677 on add_unittest_base into 61874e3 on master.

@coveralls
Copy link

coveralls commented Oct 21, 2017

Coverage Status

Coverage increased (+5.5%) to 39.498% when pulling d7d8e52 on add_unittest_base into 61874e3 on master.

@syssi
Copy link
Collaborator

syssi commented Oct 23, 2017

Cool! Could be merged. I will try to adopt the test for a air purifier soon!

@rytilahti rytilahti merged commit c859d51 into master Oct 23, 2017
@rytilahti rytilahti deleted the add_unittest_base branch October 23, 2017 20:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants