-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9e7e150
commit a526777
Showing
5 changed files
with
57 additions
and
23 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,27 @@ | ||
import tempfile | ||
from zero_hid import Keyboard | ||
|
||
from utils import random_file | ||
|
||
def test_typing(): | ||
with tempfile.TemporaryDirectory(ignore_cleanup_errors=True) as tmpdir: | ||
k = Keyboard(f'{tmpdir}/test') | ||
path = random_file() | ||
with open(path, 'ab+') as f: | ||
k = Keyboard(f) | ||
k.type("Hello world!") | ||
f.seek(0) | ||
expect = b'\x02\x00\x0b\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x08\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x0f\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x0f\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x12\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00,\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x1a\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x12\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x15\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x0f\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x07\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x1e\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' | ||
assert expect == f.read() | ||
|
||
data = f.read() | ||
expect = b'\x02\x00\x0b\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x08\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x0f\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x0f\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x12\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00,\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x1a\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x12\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x15\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x0f\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x07\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x1e\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' | ||
assert expect == data | ||
|
||
|
||
|
||
|
||
def test_release(): | ||
with tempfile.TemporaryDirectory(ignore_cleanup_errors=True) as tmpdir: | ||
k = Keyboard(f'{tmpdir}/test') | ||
path = random_file() | ||
with open(path, 'ab+') as f: | ||
k = Keyboard(f) | ||
k.release() | ||
f.seek(0) | ||
assert b'\x00\x00\x00\x00\x00\x00\x00\x00' == f.read() | ||
data = f.read() | ||
|
||
assert b'\x00\x00\x00\x00\x00\x00\x00\x00' == data | ||
|
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 |
---|---|---|
@@ -1,20 +1,24 @@ | ||
import tempfile | ||
from zero_hid import Mouse | ||
|
||
from utils import random_file | ||
|
||
def test_left_click(): | ||
with tempfile.TemporaryDirectory(ignore_cleanup_errors=True) as tmpdir: | ||
m = Mouse(f'{tmpdir}/test') | ||
m.left_click() | ||
m.close() | ||
f.seek(0) | ||
assert b'\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00' == f.read() | ||
path = random_file() | ||
with open(path, 'ab+') as f: | ||
m = Mouse(f) | ||
m.left_click() | ||
f.seek(0) | ||
data = f.read() | ||
f.close() | ||
assert b'\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00' == data | ||
|
||
|
||
def test_move(): | ||
with tempfile.TemporaryDirectory(ignore_cleanup_errors=True) as tmpdir: | ||
m = Mouse(f'{tmpdir}/test') | ||
m.move_relative(100, 100) | ||
m.close() | ||
f.seek(0) | ||
assert b'\x00dd\x00\x00' == f.read() | ||
path = random_file() | ||
with open(path, 'ab+') as f: | ||
m = Mouse(f) | ||
m.move_relative(100, 100) | ||
f.seek(0) | ||
data = f.read() | ||
f.close() | ||
assert b'\x00dd\x00\x00' == data |
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,11 @@ | ||
import tempfile | ||
import os | ||
|
||
def random_file(): | ||
# Create a temporary directory | ||
temp_dir = tempfile.mkdtemp() | ||
|
||
# Generate a random file name | ||
file_name = tempfile.NamedTemporaryFile(dir=temp_dir, delete=False).name | ||
# Return the path of the random file | ||
return file_name |
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