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 some tests to vacuum #100

Merged
merged 4 commits into from
Nov 1, 2017
Merged
Changes from all 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
184 changes: 184 additions & 0 deletions miio/tests/test_vacuum.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
from unittest import TestCase
import pytest
from .dummies import DummyDevice
import datetime
from miio import Vacuum, VacuumStatus, VacuumException

Choose a reason for hiding this comment

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

'miio.VacuumStatus' imported but unused
'miio.VacuumException' imported but unused



class DummyVacuum(DummyDevice, Vacuum):
STATE_CHARGING = 8
STATE_CLEANING = 5
STATE_IDLE = 3
STATE_HOME = 6
STATE_SPOT = 11
STATE_ERROR = 12
STATE_PAUSED = 10
STATE_MANUAL = 7
def __init__(self, *args, **kwargs):

Choose a reason for hiding this comment

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

expected 1 blank line, found 0

self.state = {
'state': 8,
'dnd_enabled': 1,
'clean_time': 0,
'msg_ver': 4,
'map_present': 1,
'error_code': 0,
'in_cleaning': 0,
'clean_area': 0,
'battery': 100,
'fan_power': 20,
'msg_seq': 320
}

self.return_values = {
'get_status': self.vacuum_state,
'app_start': lambda x: self.change_mode("start"),
'app_stop': lambda x: self.change_mode("stop"),
'app_pause': lambda x: self.change_mode("pause"),
'app_spot': lambda x: self.change_mode("spot"),
'app_charge': lambda x: self.change_mode("charge")
}

super().__init__(args, kwargs)

def change_mode(self, new_mode):
if new_mode == "spot":
self.state["state"] = DummyVacuum.STATE_SPOT
elif new_mode == "home":
self.state["state"] = DummyVacuum.STATE_HOME
elif new_mode == "pause":
self.state["state"] = DummyVacuum.STATE_PAUSED
elif new_mode == "start":
self.state["state"] = DummyVacuum.STATE_CLEANING
elif new_mode == "stop":
self.state["state"] = DummyVacuum.STATE_IDLE
elif new_mode == "charge":
self.state["state"] = DummyVacuum.STATE_CHARGING

def vacuum_state(self, _):
return [self.state]


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


@pytest.mark.usefixtures("dummyvacuum")
class TestVacuum(TestCase):
def status(self):
return self.device.status()

def test_status(self):
self.device._reset_state()
status = self.status()
assert status.is_on is False
assert status.dnd is True
assert status.clean_time == datetime.timedelta()
assert status.error_code == 0
assert status.error == "No error"
assert status.fanspeed == self.device.start_state["fan_power"]
assert status.battery == self.device.start_state["battery"]

def test_status_with_errors(self):
errors = {5: "Clean main brush",
19: "Unpowered charging station"}

for errcode, error in errors.items():
self.device.state["state"] = self.device.STATE_ERROR
self.device.state["error_code"] = errcode
assert self.status().is_on is False
assert self.status().got_error is True
assert self.status().error_code == errcode
assert self.status().error == error

def test_start_and_stop(self):
assert self.status().is_on is False
self.device.start()
assert self.status().is_on is True
assert self.status().state_code == self.device.STATE_CLEANING
self.device.stop()
assert self.status().is_on is False

def test_spot(self):
assert self.status().is_on is False
self.device.spot()
assert self.status().is_on is True
assert self.status().state_code == self.device.STATE_SPOT
self.device.stop()
assert self.status().is_on is False

def test_pause(self):
self.device.start()
assert self.status().is_on is True
self.device.pause()
assert self.status().state_code == self.device.STATE_PAUSED

def test_home(self):
self.device.start()
assert self.status().is_on is True
self.device.home()
assert self.status().state_code == self.device.STATE_CHARGING
# TODO pause here and update to idle/charging and assert for that?
# Another option is to mock that app_stop mode is entered before
# the charging is activated.

@pytest.mark.xfail
def test_manual_control(self):
self.fail()

@pytest.mark.skip("unknown handling")
def test_log_upload(self):
self.fail()

@pytest.mark.xfail
def test_consumable_status(self):
self.fail()

@pytest.mark.skip("consumable reset is not implemented")
def test_consumable_reset(self):
self.fail()

@pytest.mark.xfail
def test_map(self):
self.fail()

@pytest.mark.xfail
def test_clean_history(self):
self.fail()

@pytest.mark.xfail
def test_clean_details(self):
self.fail()

@pytest.mark.skip("hard to test")
def test_find(self):
self.fail()

@pytest.mark.xfail
def test_timer(self):
self.fail()

@pytest.mark.xfail
def test_dnd(self):
self.fail()

@pytest.mark.xfail
def test_fan_speed(self):
self.fail()

@pytest.mark.xfail
def test_sound_info(self):
self.fail()

@pytest.mark.xfail
def test_serial_number(self):
self.fail()

@pytest.mark.xfail
def test_timezone(self):
self.fail()

@pytest.mark.xfail
def test_raw_command(self):
self.fail()