-
Notifications
You must be signed in to change notification settings - Fork 65
/
test_extensions.py
69 lines (48 loc) · 1.51 KB
/
test_extensions.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import asyncio
import random
import string
import time
import unittest
import pytest
from ahk import AHK
from ahk.extensions import Extension
sleep = time.sleep
function_name = 'AHKDoSomething'
ext_text = f'''\
{function_name}(ByRef command) {{
arg := command[2]
return FormatResponse("ahk.message.StringResponseMessage", Format("test{{}}", arg))
}}
'''
async_extension = Extension(script_text=ext_text)
@async_extension.register
def do_something(ahk, arg: str) -> str:
res = ahk.function_call(function_name, [arg])
return res
class TestExtensions(unittest.TestCase):
def setUp(self) -> None:
self.ahk = AHK(extensions=[async_extension])
def tearDown(self) -> None:
self.ahk._transport._proc.kill()
time.sleep(0.2)
def test_ext_explicit(self):
res = self.ahk.do_something('foo')
assert res == 'testfoo'
class TestExtensionsAuto(unittest.TestCase):
def setUp(self) -> None:
self.ahk = AHK(extensions='auto')
def tearDown(self) -> None:
self.ahk._transport._proc.kill()
time.sleep(0.2)
def test_ext_auto(self):
res = self.ahk.do_something('foo')
assert res == 'testfoo'
class TestNoExtensions(unittest.TestCase):
def setUp(self) -> None:
self.ahk = AHK()
self.ahk.get_mouse_position() # cause daemon to start
def tearDown(self) -> None:
self.ahk._transport._proc.kill()
time.sleep(0.2)
def test_ext_no_ext(self):
assert not hasattr(self.ahk, 'do_something')