-
Notifications
You must be signed in to change notification settings - Fork 426
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactoring(logitech_receiver/notifications): create tests before cre…
…ating BOLT_PAIRING_ERRORS enums
- Loading branch information
Showing
2 changed files
with
86 additions
and
27 deletions.
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,44 @@ | ||
from logitech_receiver import notifications, hidpp10_constants | ||
from logitech_receiver.base import HIDPPNotification | ||
from logitech_receiver.hidpp10_constants import Registers | ||
from logitech_receiver.receiver import Receiver | ||
|
||
|
||
# Create a mock LowLevelInterface for testing | ||
class MockLowLevelInterface: | ||
This comment has been minimized.
Sorry, something went wrong. |
||
def open_path(self, path): | ||
pass | ||
|
||
def find_paired_node_wpid(self, receiver_path: str, index: int): | ||
pass | ||
|
||
def ping(self, handle, number, long_message=False): | ||
pass | ||
|
||
def request(self, handle, devnumber, request_id, *params, **kwargs): | ||
pass | ||
|
||
def close(self, handle): | ||
pass | ||
|
||
|
||
def test__process_receiver_notification_discovery_status_notification_bolt_pairing_error(): | ||
This comment has been minimized.
Sorry, something went wrong.
MattHag
Collaborator
|
||
receiver: Receiver = Receiver(MockLowLevelInterface(), None, {}, True, None, None) | ||
notification = HIDPPNotification(0, 0, Registers.DISCOVERY_STATUS_NOTIFICATION, 0, b'\x01') | ||
|
||
result = notifications._process_receiver_notification(receiver, notification) | ||
|
||
assert result | ||
assert receiver.pairing.error == hidpp10_constants.BOLT_PAIRING_ERRORS['device_timeout'] | ||
assert receiver.pairing.new_device is None | ||
|
||
|
||
def test__process_receiver_notification_pairing_status_notification_bolt_pairing_error(): | ||
receiver: Receiver = Receiver(MockLowLevelInterface(), None, {}, True, None, None) | ||
notification = HIDPPNotification(0, 0, Registers.PAIRING_STATUS_NOTIFICATION, 0, b'\x02') | ||
|
||
result = notifications._process_receiver_notification(receiver, notification) | ||
|
||
assert result | ||
assert receiver.pairing.error == hidpp10_constants.BOLT_PAIRING_ERRORS['failed'] | ||
assert receiver.pairing.new_device is None |
1 comment
on commit 620e7a6
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.
Nice, that covers a quite huge function and makes it more readable 👏
Put type hint related imports into a condition, so they o not become a hard dependency.
if typing.TYPE_CHECK...