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_01_ScriptFunction(self):
"""Testing creating and using a Function through a Script object."""
tests = (
(1, 1),
('2', 2),
('3', '4'),
(10, 11),
(100, 1000),
)
script = ahk.Script()
# Define our good function
add = script.function('add', int, '(x, y)', 'return x + y')
self.assertIsInstance(add, ahk.Function,
msg="Non-function {0} returned!".format(add))
# Test expected exceptions
with self.assertRaises(AttributeError):
script.function('_badname')
script.function('function')
script.function('add')
# Test with an assortment of values
for x, y in tests:
result = script.add(x, y)
expect = int(x) + int(y)
self.assertEqual(result, expect,
msg="Unexpected result {0}, expected {1}!".format(
result, expect))
with self.assertRaises(ValueError):
# Error during type conversion
def test_00_Function(self):
"""Testing Function wrapper object."""
tests = (
(1, 1),
('2', 2),
('3', '4'),
(10, 11),
(100, 1000),
)
# Startup
ahk.start()
ahk.ready()
# Define our function
add = ahk.Function('add', int, '(x, y)', 'return x + y')
# Test with an assortment of values
for x, y in tests:
result = add(x, y)
expect = int(x) + int(y)
self.assertEqual(result, expect,
msg="Unexpected result {0}, expected {1}!".format(
result, expect))
with self.assertRaises(ValueError):
# Error during type conversion
add('abc', 'efg')
# Cleanup
ahk.terminate()