Example #1
0
    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()
Example #2
0
    def test_01_start(self):
        """Testing ahk.start function."""
        if ahk.ready(nowait=True):
            raise RuntimeError("ahk script started before start test!")

        # Test basic startup
        ahk.start()
        self.assertTrue(ahk.ready(retries=15),
                        msg="Library Un-initialized after 15 tests?")
        ahk.terminate()
Example #3
0
    def test_02_terminate(self):
        """Testing terminating an ahk thread."""
        if ahk.ready(nowait=True):
            raise RuntimeError("ahk script started before start test!")

        # Confirm start, then confirm termination
        ahk.start()
        self.assertTrue(ahk.ready(retries=15),
                        msg="Library Un-initialized after 15 tests?")
        ahk.terminate()
        self.assertFalse(ahk.ready(nowait=True), msg="Thread not terminated!")
Example #4
0
 def tearDown(self):
     """Clean test environment."""
     # This fails if the terminate function fails.
     ahk.terminate()
     if os.path.exists(self.tempfilename):
         os.remove(self.tempfilename)