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_delay(self):
"""Testing control delay decorator."""
ctl = ahk.Control(self.script, store=False)
# Set the control delay and check that it is set
delay = 50
ctl.set_delay(control=delay)
self.assertEqual(ctl._cdelay, delay, msg="Set delay not stored?")
# Mock out ahk.execute in the control module so no commands actually run
with mock.patch('ahk.control.execute') as exc:
outer_delay = ahk.get("A_ControlDelay")
inner_delay = list() # Object in outer scope
def store(cmd):
"""execute replacement for mock."""
# Object in outer scope used in closure to store a value
inner_delay.append(int(ahk.get("A_ControlDelay")))
if 'send' not in cmd.lower():
#print cmd, inner_delay
ahk.execute(cmd)
exc.side_effect = store # set store to be called when execute is
# Call a delayed method and ensure that the stored delay is
# in effect only in the method call
ctl.send()
inner_delay = inner_delay[-1] # Unwrap inner value
self.assertNotEqual(outer_delay, inner_delay,
msg="Inner delay {0} is the same as outer {1}!".format(
def store(cmd):
"""execute replacement for mock."""
# Object in outer scope used in closure to store a value
inner_delay.append(int(ahk.get("A_ControlDelay")))
if 'send' not in cmd.lower():
#print cmd, inner_delay
ahk.execute(cmd)