-
-
Notifications
You must be signed in to change notification settings - Fork 563
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
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
||
|
||
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): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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() |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.VacuumStatus' imported but unused
'miio.VacuumException' imported but unused