コード例 #1
0
ファイル: test_ahk.py プロジェクト: kelvinwop/pyahk
 def test_04_execute(self):
     """Testing executing script strings."""
     val = 0
     arr = [5, 6, 3, 7, 2, 4, 1, 8, 9]
     ahk.start()
     ahk.ready()
     # First set a test variable to a known value
     self.assertTrue(ahk.set("test", val),
                     msg="Setting value reported as failed by ahk!")
     # Execute a command that changes the value
     self.assertTrue(ahk.execute("test := test+1"),
                     msg="Execute reported failure!")
     # Check the value has changed, and is correct
     value = int(ahk.get("test"))
     self.assertNotEqual(val, value, msg="Value unchanged after execution?")
     self.assertEqual(
         value,
         1,
         msg="Unexpected value {0} after execution!".format(value))
     # Execute a more complicated set of commands and check the result
     self.assertTrue(ahk.execute("arr={0}\nsort arr, N D,".format(",".join(
         str(i) for i in arr))),
                     msg="Execute reported failure!")
     value = ahk.get("arr")
     arr = ",".join(str(i) for i in sorted(arr))
     #print "result:\n\t{0}\n\t{1}".format(value, arr)
     self.assertEqual(
         arr,
         value,
         msg="Unexpected result:\n\t{0} not equal to\n\t{1}".format(
             value, arr))
コード例 #2
0
ファイル: test_ahk.py プロジェクト: kelvinwop/pyahk
    def test_03_setget(self):
        """Test setting/getting variable value."""
        test_vals = [
            1, 5, 50, 500, 'abc', 'a longer string',
            'a string with\nspecial characters!'
        ]

        ahk.start()
        ahk.ready()
        # Test setting and then getting various variable values
        for val in test_vals:
            # Check setting is reported successful
            self.assertTrue(ahk.set("test", val),
                            msg="Setting value reported as failed by ahk!")

            # Check that setting was successful
            value = ahk.get("test")
            self.assertEqual(
                str(val),
                value,
                msg="Returned value {0} doesn't match {1}!".format(value, val))

        # Test getting a non-existent variable
        self.assertEqual(
            "",
            ahk.get("nonexistent"),
            msg="Got non-empty result from non-existent variable!")
コード例 #3
0
ファイル: test_ahk.py プロジェクト: kelvinwop/pyahk
 def test_12_exec_line(self):
     """Testing line-wise execution."""
     ahk.start()
     ahk.ready()
     # Test retrieving the current line
     self.assertNotEqual(ahk.exec_line(mode=0),
                         0,
                         msg="Got null pointer to first line?")
     # Add lines by string
     ahk.set('test', 0)
     addr = ahk.add_lines("test := test+5\n")
     res = ahk.get("test")
     self.assertEqual(res,
                      "5",
                      msg="Value={0}, script not evaluated?".format(res))
     # Executing the saved line should increase test by 5
     ahk.exec_line(addr, wait=True)
     res = ahk.get("test")
     self.assertEqual(res,
                      "10",
                      msg="Value={0}, line not executed?".format(res))
コード例 #4
0
ファイル: test_ahk.py プロジェクト: kelvinwop/pyahk
 def test_08_post(self):
     """Testing posting function call."""
     ahk.start()
     ahk.ready()
     # Posting to a non-existent function should return false
     self.assertFalse(
         ahk.post('nonexistent'),
         msg="Success reported posting to non-existent function!")
     # Define a new function that changes the environment
     ahk.add_lines("""
                   changer() {
                       ErrorLevel = 1
                   }
                   """)
     # Set ErrorLevel then check value after posting function
     ahk.set("ErrorLevel", 0)
     # The following raises WindowsError access violation
     self.assertTrue(ahk.post('changer'),
                     msg="Failed to find an existing function?")
     self.assertNotEqual(0,
                         ahk.get("ErrorLevel"),
                         msg="Internal variable unchanged?")