-
-
Notifications
You must be signed in to change notification settings - Fork 569
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
Tests for the Chuangmi IR controller #184
Merged
Merged
Changes from 12 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
e69a255
Response examples added.
syssi 8d24ea7
Tests for the Chuangmi IR controller added.
syssi ee427d6
Missing blank line added.
syssi 5557f99
Empty state added and dummy implementation used.
syssi 8cee2a3
Missing DummyDevice added.
syssi d8be994
Typo fixed.
syssi 2f59303
The frequency parameter is optional now.
syssi 6a36fb6
Lambda removed.
syssi 2d6bd6d
Whitespace removed. Typo fixed.
syssi dbb87fc
Proper call of the validation method.
syssi 5f86165
Parameter issue fixed.
syssi 82d85ae
Test for send_pronto added.
syssi db383a9
Blank line added.
syssi 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
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,77 @@ | ||
from unittest import TestCase | ||
from miio import ChuangmiIr | ||
from miio.chuangmi_ir import ChuangmiIrException | ||
from .dummies import DummyDevice | ||
import pytest | ||
import base64 | ||
|
||
PROSONIC_POWER_ON = 'Z6VPAAUCAABgAgAAxQYAAOUIAACUEQAAqyIAADSeAABwdQEAAAAAAAA' \ | ||
'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABFEBAQEBAQEBAgICAgIC' \ | ||
'AgEBAgECAQEBAQIBAgECAgICBgNXA1cDUA' | ||
|
||
PROSONIC_POWER_ON_PROTON = '0000006C00220002015B00AD001600160016001600160016' \ | ||
'001600160016001600160016001600160016001600160041' \ | ||
'001600410016004100160041001600410016004100160041' \ | ||
'001600160016001600160041001600160016004100160016' \ | ||
'001600160016001600160016001600410016001600160041' \ | ||
'001600160016004100160041001600410016004100160623' \ | ||
'015B005700160E6E' | ||
|
||
class DummyChuangmiIr(DummyDevice, ChuangmiIr): | ||
def __init__(self, *args, **kwargs): | ||
self.state = {} | ||
self.return_values = { | ||
'miIO.ir_learn': lambda x: True, | ||
'miIO.ir_read': lambda x: True, | ||
'miIO.ir_play': self._ir_play_input_validation, | ||
} | ||
super().__init__(args, kwargs) | ||
|
||
@staticmethod | ||
def _ir_play_input_validation(payload): | ||
try: | ||
base64.b64decode(payload['code']) | ||
return True | ||
except TypeError: | ||
return False | ||
|
||
|
||
@pytest.fixture(scope="class") | ||
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 2 blank lines, found 1 |
||
def chuangmiir(request): | ||
request.cls.device = DummyChuangmiIr() | ||
# TODO add ability to test on a real device | ||
|
||
|
||
@pytest.mark.usefixtures("chuangmiir") | ||
class TestChuangmiIr(TestCase): | ||
def test_learn(self): | ||
assert self.device.learn() is True | ||
assert self.device.learn(30) is True | ||
|
||
with pytest.raises(ChuangmiIrException): | ||
self.device.learn(-1) | ||
|
||
with pytest.raises(ChuangmiIrException): | ||
self.device.learn(1000001) | ||
|
||
def test_read(self): | ||
assert self.device.read() is True | ||
assert self.device.read(30) is True | ||
|
||
with pytest.raises(ChuangmiIrException): | ||
self.device.read(-1) | ||
|
||
with pytest.raises(ChuangmiIrException): | ||
self.device.read(1000001) | ||
|
||
def test_play(self): | ||
assert self.device.play(PROSONIC_POWER_ON) is True | ||
assert self.device.play(PROSONIC_POWER_ON, 19200) is True | ||
|
||
def test_play_pronto(self): | ||
assert self.device.play_pronto(PROSONIC_POWER_ON_PROTON) is True | ||
assert self.device.play_pronto(PROSONIC_POWER_ON_PROTON, 0) is True | ||
assert self.device.play_pronto(PROSONIC_POWER_ON_PROTON, 1) is True | ||
|
||
with pytest.raises(ChuangmiIrException): | ||
self.device.play_pronto(PROSONIC_POWER_ON_PROTON, -1) |
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.
expected 2 blank lines, found 1