Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import time
from pathlib import Path
from asciimatics.event import KeyboardEvent, MouseEvent
from asciimatics.screen import Screen
from aria2p import interface as tui
from . import SESSIONS_DIR, Aria2Server
tui.Interface.frames = 20 # reduce tests time
class SpecialEvent:
RESIZE = 1
PASS_N_FRAMES = 2
PASS_N_TICKS = 3
RAISE = 4
def __init__(self, event_type, value=None):
self.type = event_type
self.value = value
class Event:
resize = SpecialEvent(SpecialEvent.RESIZE)
pass_frame = SpecialEvent(SpecialEvent.PASS_N_FRAMES, 1)
def get_interface(patcher, api=None, events=None, append_q=True):
if not events:
events = []
if append_q:
events.append(KeyboardEvent(ord("q")))
class MockedManagedScreen:
def __enter__(self):
return MockedScreen(events)
def __exit__(self, exc_type, exc_val, exc_tb):
pass
patcher.setattr(tui, "ManagedScreen", MockedManagedScreen)
return tui.Interface(api=api)
def test_mouse_event(monkeypatch):
reverse = tui.Interface.reverse
with Aria2Server(port=7608, session=SESSIONS_DIR / "3-magnets.txt") as server:
interface = run_interface(
monkeypatch,
server.api,
events=[MouseEvent(x=tui.Interface.x_offset, y=tui.Interface.y_offset, buttons=MouseEvent.LEFT_CLICK)] * 2,
)
assert interface.sort == 0
assert interface.reverse is not reverse