Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_00_init(self):
"""Testing that script was initialized correctly."""
scr = ahk.Script()
self.assertTrue(ahk.ready(nowait=True),
msg="AHK not ready after init?")
self.assertIsNotNone(scr.Clipboard,
msg="Special Clipboard variable not initialized!")
self.assertIsNotNone(scr.ErrorLevel,
msg="Special ErrorLevel variable not initialized!")
def test_01_init(self):
"""Testing control initialization."""
# Mock out script instance
scr = mock.Mock(spec=self.script)
# Set winExist return to known value
def effect(title, *args, **kwargs):
if 'error' in title.lower():
return None
return 42
scr.winExist.side_effect = effect
# First test no store and parameter set
inparams = ('title', 'text', 'extitle', 'extext')
ctl = ahk.Control(scr, *inparams, store=False)
outparams = ctl._params() #NOTE use of private method could break!
self.assertEqual(inparams, outparams,
msg="Retrieved params {0} don't match input {1}!".format(
outparams, inparams))
# Next check HWND storage behavior
with self.assertRaises(NameError):
ctl = ahk.Control(scr, title='error') # store=True but window doesn't exist
scr.reset_mock()
ctl = ahk.Control(scr, *inparams)
self.assertEqual(ctl.hwnd, 42, msg="Wrong HWND stored?")
outparams = ctl._params() #NOTE use of private method could break!
title = outparams[0].lower()
self.assertTrue('ahk_id' in title and '42' in title,
msg="HWND param \"{0}\" incorrectly formatted!".format(title))
self.assertFalse(''.join(outparams[1:]), # Extra params are set to ''
msg="Retrieved params {0} contain unexpected value!".format(
def test_00_init(self):
"""Testing that script was initialized correctly."""
scr = ahk.Script()
self.assertTrue(ahk.ready(nowait=True),
msg="AHK not ready after init?")
self.assertIsNotNone(scr.Clipboard,
msg="Special Clipboard variable not initialized!")
self.assertIsNotNone(scr.ErrorLevel,
msg="Special ErrorLevel variable not initialized!")
def a_down():
time.sleep(0.5)
ahk = AHK()
ahk.key_down('a')
import sys
import os
import time
project_root = os.path.abspath(os.path.join(os.path.dirname(os.path.abspath(__file__)), '../..'))
sys.path.insert(0, project_root)
from ahk import AHK
from ahk.window import WindowNotFoundError
import pytest
import subprocess
ahk = AHK()
def test_get_calculator():
p = None
try:
p = subprocess.Popen('notepad')
time.sleep(1) # give notepad time to start up
win = ahk.win_get(title='Untitled - Notepad')
assert win
assert win.position
finally:
if p is not None:
p.terminate()
def test_win_close():
p = None
try:
from behave.matchers import RegexMatcher
from ahk import AHK
from behave_classy import step_impl_base
Base = step_impl_base()
class AHKSteps(AHK, Base):
@Base.given(u'the mouse position is ({xpos:d}, {ypos:d})')
def given_mouse_move(self, xpos, ypos):
self.mouse_move(x=xpos, y=ypos)
@Base.when(u'I move the mouse (UP|DOWN|LEFT|RIGHT) (\d+)px', matcher=RegexMatcher)
def move_direction(self, direction, px):
px = int(px)
if direction in ('UP', 'DOWN'):
axis = 'y'
else:
axis = 'x'
if direction in ('LEFT', 'UP'):
px = px * -1
kwargs = {axis: px, 'relative': True}
self.mouse_move(**kwargs)
def test_no_executable_raises_error():
check_pwd()
with mock.patch.dict(os.environ, {'PATH': ''}, clear=True):
with pytest.raises(ExecutableNotFoundError):
AHK()
def test_env_var_takes_precedence_over_path():
check_pwd()
actual_path = AHK().executable_path
ahk_location = os.path.abspath(os.path.dirname(actual_path))
with mock.patch.dict(os.environ, {'PATH': ahk_location, 'AHK_PATH':'C:\\expected\\path\\to\\ahk.exe'}):
ahk = AHK()
assert ahk.executable_path == 'C:\\expected\\path\\to\\ahk.exe'
def setUp(self):
"""
Record all open windows
:return:
"""
self.ahk = AHK()
self.before_windows = self.ahk.windows()
im = Image.new('RGB', (20, 20))
for coord in product(range(20), range(20)):
im.putpixel(coord, (255, 0, 0))
self.im = im
im.show()
time.sleep(2)
def setUp(self):
"""
Record all open windows
:return:
"""
self.ahk = AHK()
self.before_windows = self.ahk.windows()
self.p = subprocess.Popen('notepad')
time.sleep(1)
self.notepad = self.ahk.find_window(title=b'Untitled - Notepad')