-
-
Notifications
You must be signed in to change notification settings - Fork 0
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
f70334a
commit 6581c80
Showing
20 changed files
with
241 additions
and
37 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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[run] | ||
omit = ./testing/* |
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
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,3 @@ | ||
# from replay_wizard import capture | ||
# | ||
# capture('one') |
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,2 +1,4 @@ | ||
[MAIN] | ||
ignore-paths=./replay_wizard/package.py | ||
disable= | ||
W0621, # Redefining name outer scope (pytest fixtures) |
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
""" | ||
PyGenesis package | ||
ReplayWizard package | ||
""" | ||
from .main import info | ||
#from .capturing import capture |
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,41 @@ | ||
# """ | ||
# Main module | ||
# """ | ||
# from pynput import keyboard | ||
# | ||
# | ||
# def on_press(key, f): | ||
# try: | ||
# print('alphanumeric key {0} pressed'.format( | ||
# key.char)) | ||
# f.write(f'{key.char} pressed\n') | ||
# except AttributeError: | ||
# print('special key {0} pressed'.format( | ||
# key)) | ||
# | ||
# | ||
# def on_release(key, f): | ||
# if key == keyboard.Key.esc: | ||
# # Stop listener | ||
# return False | ||
# print('{0} released'.format( | ||
# key)) | ||
# f.write(f'{key.char} released\n') | ||
# | ||
# | ||
# def capture(name): | ||
# file_name = f'{name}.sequence' | ||
# with open(file_name, 'w', encoding='utf-8') as f: | ||
# on_press_handler = lambda key: on_press(key, f) | ||
# on_release_handler = lambda key: on_release(key, f) | ||
# | ||
# with keyboard.Listener( | ||
# on_press=on_press_handler, | ||
# on_release=on_release_handler) as listener: | ||
# listener.join() | ||
# | ||
# # ...or, in a non-blocking fashion: | ||
# # listener = keyboard.Listener( | ||
# # on_press=on_press, | ||
# # on_release=on_release) | ||
# # listener.start() |
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,13 +0,0 @@ | ||
""" | ||
Main module | ||
""" | ||
|
||
|
||
def info(): | ||
""" | ||
ReplayWizard info | ||
:return: ReplayWizard usage info | ||
""" | ||
result = ('This is the mock of ReplayWizard package: ' | ||
'https://github.com/quillcraftsman/replay-wizard') | ||
return result | ||
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,5 @@ | ||
""" | ||
Models package | ||
""" | ||
from .action import Action, Subtypes | ||
from .sequence import Sequence |
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,24 @@ | ||
""" | ||
Action module | ||
""" | ||
from enum import Enum | ||
from pydantic import BaseModel, ConfigDict | ||
|
||
|
||
class Subtypes(str, Enum): | ||
""" | ||
Action subtype | ||
""" | ||
KEYBOARD = 'keyboard' | ||
MOUSE = 'mouse' | ||
|
||
|
||
class Action(BaseModel): | ||
""" | ||
Action model | ||
""" | ||
model_config = ConfigDict(frozen=True) | ||
|
||
subtype: Subtypes | ||
value: str | ||
timedelta: float |
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,26 @@ | ||
""" | ||
Sequence module | ||
""" | ||
from typing import List | ||
from pydantic import BaseModel | ||
from .action import Action | ||
|
||
|
||
class Sequence(BaseModel): | ||
""" | ||
Action sequence | ||
""" | ||
name: str | ||
actions: List[Action] | ||
|
||
def __len__(self): | ||
return len(self.actions) | ||
|
||
def add(self, new_action: Action): | ||
""" | ||
Add action to sequence | ||
:param new_action: Action to add | ||
:return: None | ||
""" | ||
self.actions.append(new_action) |
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 +1,2 @@ | ||
pynput==1.7.6 | ||
pynput==1.7.6 | ||
pydantic==2.6.3 |
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 was deleted.
Oops, something went wrong.
File renamed without changes.
Empty file.
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,29 @@ | ||
""" | ||
Pytest fixtures | ||
""" | ||
from pytest import fixture | ||
from replay_wizard.models import Action, Subtypes | ||
|
||
|
||
@fixture | ||
def put_a_action(): | ||
""" | ||
Simple action fixture | ||
""" | ||
return Action( | ||
subtype=Subtypes.KEYBOARD, | ||
value='a', | ||
timedelta=0.1, | ||
) | ||
|
||
|
||
@fixture | ||
def put_a_action_dict(): | ||
""" | ||
Action as dict fixture | ||
""" | ||
return { | ||
'value': 'a', | ||
'subtype': 'keyboard', | ||
'timedelta': 0.1, | ||
} |
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,30 @@ | ||
""" | ||
Test Action model module | ||
""" | ||
import pytest | ||
from pydantic import ValidationError | ||
from replay_wizard.models import Subtypes | ||
|
||
|
||
def test_action(put_a_action): | ||
""" | ||
Test simple action | ||
""" | ||
assert put_a_action.value == 'a' | ||
assert put_a_action.subtype == Subtypes.KEYBOARD | ||
assert put_a_action.timedelta == 0.1 | ||
|
||
|
||
def test_action_is_frozen(put_a_action): | ||
""" | ||
Test that action is frozen (immutable) | ||
""" | ||
with pytest.raises(ValidationError): | ||
put_a_action.value = 'b' | ||
|
||
|
||
def test_to_dict(put_a_action, put_a_action_dict): | ||
""" | ||
Test action to dict | ||
""" | ||
assert put_a_action_dict == put_a_action.model_dump() |
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,65 @@ | ||
""" | ||
Test sequence module | ||
""" | ||
import pytest | ||
from replay_wizard.models import Action, Sequence, Subtypes | ||
|
||
|
||
@pytest.fixture | ||
def empty_sequence(): | ||
""" | ||
Empty sequence fixture | ||
""" | ||
return Sequence( | ||
name='open youtube', | ||
actions=[] | ||
) | ||
|
||
|
||
def test_full_sequence(put_a_action): | ||
""" | ||
Test full sequence data | ||
""" | ||
put_b = Action( | ||
subtype=Subtypes.KEYBOARD, | ||
value='b', | ||
timedelta=0.1, | ||
) | ||
Sequence( | ||
name='input a then b', | ||
actions=[put_a_action, put_b] | ||
) | ||
|
||
|
||
def test_len(empty_sequence): | ||
""" | ||
Test __len__ method | ||
""" | ||
assert len(empty_sequence) == 0 | ||
|
||
|
||
def test_add(empty_sequence, put_a_action): | ||
""" | ||
Test add method | ||
""" | ||
assert len(empty_sequence) == 0 | ||
empty_sequence.add(put_a_action) | ||
assert len(empty_sequence) == 1 | ||
|
||
|
||
def test_to_dict(empty_sequence, put_a_action, put_a_action_dict): | ||
""" | ||
Test sequence to dict | ||
""" | ||
result = { | ||
'name': 'open youtube', | ||
'actions': [], | ||
} | ||
assert result == empty_sequence.model_dump() | ||
empty_sequence.add(put_a_action) | ||
|
||
result['actions'] = [ | ||
put_a_action_dict | ||
] | ||
|
||
assert result == empty_sequence.model_dump() |