diff --git a/.gitignore b/.gitignore index 282505c..7d721df 100644 --- a/.gitignore +++ b/.gitignore @@ -152,3 +152,4 @@ cython_debug/ .vscode /documentation/.#* .rst +*.orig diff --git a/src/dtactions/__init__.py b/src/dtactions/__init__.py index 2459880..7a59eb0 100644 --- a/src/dtactions/__init__.py +++ b/src/dtactions/__init__.py @@ -41,7 +41,7 @@ """ ## version to be updated when a new release is sent to pypi: -__version__ = '1.6.2' +__version__ = '1.6.3' ##---------------------- import sys import os diff --git a/src/dtactions/autohotkeyactions.py b/src/dtactions/autohotkeyactions.py index 1c86734..9948578 100644 --- a/src/dtactions/autohotkeyactions.py +++ b/src/dtactions/autohotkeyactions.py @@ -9,6 +9,10 @@ This module contains actions via AutoHotkey +Note: most are sucking and not tested. Working are two important functions `getProgInfo` and `getModInfo`, +which give the wanted information also when Dragon is not running. (And of course the workflow functions +described below). + (see autohotkey.com) 1. the ahkexe and ahkscriptfolder are checked for at the bottom of the import procedure. @@ -24,13 +28,7 @@ 5. When scripts want information back into python, write this information into a file eg "INFOfromAHK.txt". Scripts that use this feature, should have a function in this module, in order to read the data from this file. See getProgInfo and getCurrentModule below. - -timing results: - 1 0.000 0.000 0.401 0.401 autohotkeyactions.py:456(killWindow) - 4 0.000 0.000 0.261 0.065 autohotkeyactions.py:91(getProgInfo) - 1 0.000 0.000 0.234 0.234 autohotkeyactions.py:209(ahkBringup) - 1 0.000 0.000 0.052 0.052 autohotkeyactions.py:323(GetForegroundWindow) - + """ import subprocess import shutil diff --git a/src/dtactions/monitorfunctions.py b/src/dtactions/monitorfunctions.py index 177b344..048b047 100644 --- a/src/dtactions/monitorfunctions.py +++ b/src/dtactions/monitorfunctions.py @@ -1198,7 +1198,10 @@ def test_mouse_to_other_monitor(): # canBeResized = window_can_be_resized(winHndle) mon = get_nearest_monitor_window(winHndle) others = get_other_monitors(mon) - moninfo = MONITOR_INFO[others[0]] + try: + moninfo = MONITOR_INFO[others[0]] + except IndexError: + print('test_mouse_to_other_monitor, you have only one monitor') mousefour = moninfo['Monitor'] x, y = mousefour[0] + int((mousefour[2] - mousefour[0])/2.0), mousefour[1] + int((mousefour[3] - mousefour[1])/2.0) print('middle of other monitor:', x, y) @@ -1758,13 +1761,13 @@ def do_doctest(): #print 'ra: %s'% _get_restore_area(winHndle) test_basic_values() test_taskbar_position() - test_mouse_to_other_monitor() - #restore_window(winHndle) + # test_mouse_to_other_monitor() + # restore_window(win_hndle) #test_get_nearest_monitors() - #test_individual_points() + test_individual_points() # test_move_to_other_monitor() - #test_move_around_monitor_fixed_size() + test_move_around_monitor_fixed_size() #test_center_different_sizes() #test_default_restore() # test_minimize_maximize_restore() diff --git a/src/dtactions/unimacro/extenvvars.py b/src/dtactions/unimacro/extenvvars.py index 7a5c6a9..e037f3f 100644 --- a/src/dtactions/unimacro/extenvvars.py +++ b/src/dtactions/unimacro/extenvvars.py @@ -121,39 +121,6 @@ def getFolderFromLibraryName(self, name): if name in ['LOCAL_APPDATA']: return platformdirs.windows.get_win_folder("CSIDL_LOCAL_APPDATA") - # # General case, try via shellcon! TODO: QH - # try: - # CSIDL_variable = 'CSIDL_%s'% name - # shellnumber = getattr(shellcon,CSIDL_variable, -1) - # print(f'getFolderFromLibraryName, shellnumber of "{CSIDL_variable}": {shellnumber}') - # except: - # print('getExtendedEnv, cannot find CSIDL_variable for: "%s"'% name) - # return '' - # if shellnumber < 0: - # # on some systems have SYSTEMROOT instead of SYSTEM: - # print('getExtendedEnv, cannot find CSIDL_variable for (returns -1): "%s"'% name) - # try: - # csidl_const = shellnumber - # # copied from platformdirs/windows.py: - # buf = ctypes.create_unicode_buffer(1024) - # windll = getattr(ctypes, "windll") # noqa: B009 # using getattr to avoid false positive with mypy type checker - # windll.shell32.SHGetFolderPathW(None, csidl_const, None, 0, buf) - # result = buf.value - # # # result = shell.SHGetFolderPath (0, shellnumber, 0, 0) - # # result = ctypes.windll.shell32.SHGetFolderPathW(0, shellnumber, 0, 0) - # print(f'result from SHGetFolderPathW: {result}') - # except: - # print('getFolderFromLibraryName, cannot path for CSIDL: "%s"'% name) - # return '' - - - ## extra cases: - # if name in ['Quick access', 'Snelle toegang']: - # templatesfolder =self. getExtendedEnv('TEMPLATES') - # if isdir(templatesfolder): - # QuickAccess = normpath(join(templatesfolder, "..", "Libraries")) - # if isdir(QuickAccess): - # return QuickAccess if name.upper() == 'DROPBOX': return self.getDropboxFolder() if name.upper() in ['ONEDRIVE']: @@ -316,7 +283,7 @@ def getExtendedEnv(self, var, noCache=False, displayMessage=True): result = buf.value # # result = shell.SHGetFolderPath (0, shellnumber, 0, 0) # result = ctypes.windll.shell32.SHGetFolderPathW(0, shellnumber, 0, 0) - print(f'result from SHGetFolderPathW: {result}') + # print(f'result for "{var}" via SHGetFolderPathW: {result}') except: if displayMessage: print('getExtendedEnv, cannot find in os.environ or CSIDL: "%s"'% var) @@ -337,11 +304,12 @@ def getDirectoryFromNatlinkstatus(self, envvar): # try if function in natlinkstatus: if not status: return None - for extra in ('', 'Directory', 'Dir'): - var2 = envvar + extra - if var2 in status.__dict__: - funcName = f'get{var2}' - func = getattr(status, funcName) + envvar_capped = envvar.lower() + for extra in ('', 'directory', 'dir'): + var2 = envvar_capped + extra + funcName = f'get{var2}' + func = getattr(status, funcName, None) + if func: result = func() if result: return result diff --git a/src/dtactions/unimacro/unimacroutils.py b/src/dtactions/unimacro/unimacroutils.py index 91f2f65..f9ef02d 100644 --- a/src/dtactions/unimacro/unimacroutils.py +++ b/src/dtactions/unimacro/unimacroutils.py @@ -12,7 +12,7 @@ """ #pylint:disable=C0302, C0116, C0321, R0912, R0913, R0914, R0915, W0613, C0209, W0602, W0621, R1715, W0702 -#pylint:disable=E1101 +#pylint:disable=E1101, R1735 import time import re import os @@ -639,6 +639,10 @@ def doMouse(absorrel, screenorwindow, xpos, ypos, mouse='left', nClick=1, modifi other actions are performed. Therefore the mouse state is remembered in the variable mouseState. + 2024: because of Dragon 16, with playEvents not working any more, this function restricts to + movements and clicking, not dragging any more. + + """ #pylint:disable=W0603 global mouseState @@ -736,10 +740,11 @@ def doMouse(absorrel, screenorwindow, xpos, ypos, mouse='left', nClick=1, modifi print('btn: %s, nClick: %s, current mouseState: %s'% (btn, nClick, mouseState)) if onlyMove: print('onlyMove to %s, %x'% (xp, yp)) - natlink.playEvents([(natlinkutils.wm_mousemove, xp, yp)]) + set_mouse_position(xp, yp) # absolute elif not mouseState: # ongecompliceerd if nClick > 0: - natlink.playEvents([(natlinkutils.wm_mousemove, xp, yp)]) + set_mouse_position(xp, yp) + # natlink.playEvents([(natlinkutils.wm_mousemove, xp, yp)]) if btn: if debugMode == -1: print('ButtonClick %s, %s' % (btn, nClick)) @@ -753,7 +758,8 @@ def doMouse(absorrel, screenorwindow, xpos, ypos, mouse='left', nClick=1, modifi ## Wait(0.01) elif nClick == 0: - natlink.playEvents([(natlinkutils.wm_mousemove, xp, yp)]) + set_mouse_position(xp, yp) + # natlink.playEvents([(natlinkutils.wm_mousemove, xp, yp)]) elif nClick == -1: if btn: if (xold,yold) != (xp, yp): @@ -786,7 +792,8 @@ def doMouse(absorrel, screenorwindow, xpos, ypos, mouse='left', nClick=1, modifi mouseState = 0 else: # no btn, but mouseState, simply move: - natlink.playEvents([(natlinkutils.wm_mousemove, xp, yp)]) + set_mouse_position(xp, yp) + # natlink.playEvents([(natlinkutils.wm_mousemove, xp, yp)]) def catchClick(mouse): """return reduced mouse command and nClick @@ -826,11 +833,33 @@ def buttonClick(button='left', nclick=1, modifiers=None): script = 'ButtonClick' else: script = f'ButtonClick {button},{nclick}' - print(f'buttonClick via execScript: "{script}"') + # print(f'buttonClick via execScript: "{script}"') natlink.execScript(script) - + # script = f'ButtonClick {button},{nclick}' + # # print(f'buttonClick via execScript: "{script}"') + # natlink.execScript(script) + +def set_mouse_position(xp, yp): + """set to absolute position + + when Dragon is running, with playEvents for version <= 15, + via execScript if version >= 16 + + when Dragon is NOT running, try via Autohotkey (to be done) + """ + xp, yp = int(xp), int(yp) + if natlink.isNatSpeakRunning(): + if natlink.getDNSVersion() <= 15: + natlink.playEvents( [(natlinkutils.wm_mousemove, xp, yp)]) + else: + script = f'SetMousePosition 1, {xp},{yp}' + print(f'set_mouse_position via execScript: "{script}"') + natlink.execScript(script) + else: + print('future: attempt set_mouse_position via autohotkey') + def releaseMouse(): """restores the default mouseState """ @@ -966,33 +995,39 @@ def getMousePositionActionString(absorrel, which, position): return "MP(%s, %s, %s)"% (which, x, y) def printMousePosition(absorrel, printAll = 0): - """printing function for printing the mouse positions + result = getMousePositions(absorrel, printAll=printAll) + print(result) + +def getMousePositions(absorrel, printAll = 0): + """get output for printing the mouse positions this function can be invoked by PMP and PRMP and PALLMP. these positions are recognised by the Unimacro Shorthand Commands MP and RMP """ + L = [] if printAll: - print('-'*80) + L.append('-'*80) cornerRange = list(range(4)) else: cornerRange = list(range(1)) if absorrel: # 1: relative: - print('RELATIVE MOUSE POSITIONS:') + L.append('RELATIVE MOUSE POSITIONS:') else: - print('ABSOLUTE MOUSE POSITIONS:') - for _, which in whichDict.items(): - print('---related to %s:'% which.upper()) + L.append('ABSOLUTE MOUSE POSITIONS:') + for whichnum, which in whichDict.items(): + L.append('---related to %s:'% which.upper()) for cornerPos in cornerRange: - print("%s: %s"% (cornerDict[cornerPos], getMousePositionActionString(absorrel, which, cornerPos))) + L.append("%s: %s"% (cornerDict[cornerPos], getMousePositionActionString(absorrel, whichnum, cornerPos))) if printAll: - print('-'*20) + L.append('-'*20) + return '\n'.join(L) def getMousePosition(absorrel=0, which=0, position=0): """get the parameters for doMouse absorrel: 0 abs, 1 rel - which: 1: active window, 5: client area, 0: whole screen + which: 1: active window, 3: active monitor, 5: client area, 0: whole screen position: 0: topleft, 1: topright, 2: bottomleft, 3: bottomright result: @@ -1004,6 +1039,7 @@ def getMousePosition(absorrel=0, which=0, position=0): #pylint:disable=R0912, W0612 x, y = currentPos = natlink.getCursorPos() _hndle = natlink.getCurrentModule()[2] + print(f'which: {which}') if which == 0: # complete screen width, height, xMin, yMin, xMax, yMax = monitorfunctions.getScreenRectData() @@ -1024,6 +1060,8 @@ def getMousePosition(absorrel=0, which=0, position=0): x, y = win32gui.ScreenToClient(_hndle, currentPos) rect = win32gui.GetClientRect(_hndle) width, height, xMin, yMin, xMax, yMax = getRectData(rect) + else: + raise ValueError(f'getMousePosition, variable "which" should be in (0, 1, 3, 5), not: {which}') # now test for boundaries and abs or rel: if x < xMin or x > xMax or y < yMin or y > yMax: @@ -1062,6 +1100,7 @@ def isTopWindow(hndle): """returns 1 if window is top, behaviour changed in python 2.3.4, parent = 0, no exception any more + TODO QH: is this correct? """ #pylint:disable=W0702 try: @@ -1404,8 +1443,8 @@ def addWordIfNecessary(w): print('invalid character in word to add: %s'% w) return - isInVoc = (natlink.getWordInfo(w,1) is not None) - isInActiveVoc = (natlink.getWordInfo(w,0) is not None) + isInVoc = natlink.getWordInfo(w,1) is not None + isInActiveVoc = natlink.getWordInfo(w,0) is not None if isInActiveVoc: return try: @@ -1426,7 +1465,7 @@ def deleteWordIfNecessary(w): """ if not w: return - isInActiveVoc = (natlink.getWordInfo(w,0) is not None) + isInActiveVoc = natlink.getWordInfo(w,0) is not None if isInActiveVoc: natlink.deleteWord(w) diff --git a/tests/conftest.py b/tests/conftest.py new file mode 100644 index 0000000..2238ee4 --- /dev/null +++ b/tests/conftest.py @@ -0,0 +1,15 @@ +"""common fixtures for the dtactions project +""" +import pytest +import natlink +from natlinkcore import natlinkstatus + +@pytest.fixture(scope="module") +def nl_stat(): + status = natlinkstatus.NatlinkStatus() + return status + +@pytest.fixture(scope="module") +def nat_conn(): + yield natlink.natConnect() + natlink.natDisconnect() diff --git a/tests/test_extenvvars.py b/tests/test_extenvvars.py index b94740a..26407d8 100644 --- a/tests/test_extenvvars.py +++ b/tests/test_extenvvars.py @@ -3,127 +3,173 @@ The module is in dtactions/unimacro. -Quintijn Hoogenboom, Februari 2023 + +Quintijn Hoogenboom, Februari 2023/August 2024 """ +#pylint:disable = W0621, E1101 from os.path import isdir from pathlib import Path import pytest from dtactions.unimacro import extenvvars - +import natlink thisDir = Path(__file__).parent dtactionsDir = thisDir.parent -def testStartOfInstance(): + +@pytest.fixture() +def envvars(): + return extenvvars.ExtEnvVars() + +def testStartOfInstance(envvars): """instance of ExtEnvVars starts with persistent dict of recentEnv entries, and adds at startup "~" """ - ext1 = extenvvars.ExtEnvVars() - assert len(ext1.recentEnv) == 2 - assert isdir(ext1.homeDir) + assert len(envvars.recentEnv) == 2 + assert '~' in envvars.recentEnv + assert 'HOME' in envvars.recentEnv + ## the two values are equal... + assert len(set(envvars.recentEnv.values())) == 1 + assert isdir(envvars.homeDir) -def test_getNatlinkEnvVariables(): + +@pytest.mark.parametrize("var_name", + ["natlink", "natlinkcore", "NATLINKCORE", "Natlinkcore", "dtactions"] + ) +def test_getNatlinkEnvVariables(envvars, var_name): """this tests if the natlink folders can be got with this function If "Dir" or "Directory" is missing, try to add: - eg "AhkUser" is expanded to "AhkUserDir" - (Ahk can be missing, if not installed) - + eg "AhkUser" is expanded to "AhkuserDir" (equivalent to "AhkUserDir") and "Unimacro" is expanded to "UnimacroDirectory" + + The variables are case insensitive and are converted to eg "DtactionsDirectory" """ - ext = extenvvars.ExtEnvVars() - result = ext.getExtendedEnv("%Unimacro%") - assert len(result) - assert Path(result).is_dir() - # result = ext.getExtendedEnv("%VocolaUserDirectory%") - # assert Path(result).is_dir() - # assert len(result) + result = envvars.getExtendedEnv(var_name) + if natlink.isNatSpeakRunning(): + assert len(result) + assert Path(result).is_dir() + else: + # variables are not available when natspeak is not running + assert not result + + +@pytest.mark.parametrize("var_name", + ["unimacrouser", "unimacrodata", "unimacrogrammars"] + ) +def test_getUnimacroEnvironmentVariables(envvars, var_name, nlstatus): + """testing the unimacro variables, Unimacro can be on or off + + When Unimacro is not enabled (but possibly installed), the results should be fals + + """ + result = envvars.getExtendedEnv(var_name) + if natlink.isNatSpeakRunning() and nlstatus.unimacroIsEnabled(): + assert len(result) + assert Path(result).is_dir() + else: + # variables are not available when unimacro is not available + assert not result + +# @pytest.mark.parametrize("var_name", +# ["unimacro"] +# ) +# def test_getUnimacroEnvironmentVariablesAlwaysAvailable(envvars, var_name): +# """testing the unimacro variables, Unimacro can be on or off +# +# When Unimacro is off, but Unimacro has been enabled, the result can be a valid directory. +# +# When Dragon is not running... +# +# Too confusing when the unimacro directory is shown. When it is not installed, it is not... +# +# """ +# result = envvars.getExtendedEnv(var_name) +# if natlink.isNatSpeakRunning(): +# assert len(result) +# assert Path(result).is_dir() +# else: +# assert not result + + + +def test_getAllFolderEnvironmentVariables(envvars): + """get the dict that this function gets, and test a few values + """ + D = envvars.getAllFolderEnvironmentVariables() + assert isinstance(D, dict ) + assert D['COMMON_APPDATA'] == r'C:\ProgramData' + assert D['COMMON_STARTMENU'] == r'C:\ProgramData\Microsoft\Windows\Start Menu' - # AHK maybe not installed: - result1 = ext.getExtendedEnv("%AhkUser%") - if result1: - assert Path(result1).is_dir() - result2 = ext.getExtendedEnv("%AhkUserDir%") - if result2: - assert Path(result2).is_dir() - -def test_otherEnvVariables(): + +@pytest.mark.parametrize("var_name", + ["%HOME%", "%SYSTEM%"] + ) +def test_otherEnvVariables(envvars, var_name): """this tests if "other" env variables are correctly reported + Note the precise capitalisation, and English and Dutch names are recognised here. + (When other languages are wanted, add them in extenvvars.py around line 110) + """ - ext = extenvvars.ExtEnvVars() - result = ext.getExtendedEnv("%HOME%") - assert len(result) > 0 - assert isdir(result) - result = ext.getExtendedEnv("%SYSTEM%") + result = envvars.getExtendedEnv(var_name) assert len(result) > 0 assert isdir(result) - -def test_windows_Library_dirs(): + +@pytest.mark.parametrize("first_name, alternative_name", + [ ("Music", "Muziek"), + ("Desktop", "Bureaublad"), + ("Downloads", ""), + ("Documents", "Documenten"), + ("Pictures", "Afbeeldingen"), + ("~", "HOME"), + ("Dropbox", ""), + ("OneDrive", ""), + ] + ) +def test_windows_Library_dirs(envvars, first_name, alternative_name): """most of them with platformdirs.windows, some special treatment. These are directory names, that are "shorthand", like Music, Desktop. All go to getFolderFromLibraryName, and names are currently from English or Dutch windows system. """ - ## Music - ext = extenvvars.ExtEnvVars() - result = ext.getFolderFromLibraryName('Muziek') - assert len(result) - assert Path(result).is_dir() - result2 = ext.getFolderFromLibraryName('Music') - assert result2 == result - - ## Desktop - result = ext.getFolderFromLibraryName('Desktop') - assert len(result) - assert Path(result).is_dir() - result2 = ext.getFolderFromLibraryName('Bureaublad') - assert result2 == result - - ## Downloads - result = ext.getFolderFromLibraryName('Downloads') - assert len(result) - assert Path(result).is_dir() - - ## Documents (same as PERSONAL!) - result = ext.getFolderFromLibraryName('Documents') - assert len(result) - assert Path(result).is_dir() - result2 = ext.getFolderFromLibraryName('Documenten') ## Dutch - assert result2 == result - - ## Pictures - result = ext.getFolderFromLibraryName('Pictures') - assert len(result) - assert Path(result).is_dir() - result2 = ext.getFolderFromLibraryName('Afbeeldingen') - assert result2 == result - - # ## Quick access - # result = ext.getFolderFromLibraryName('Quick access') + result1 = envvars.getFolderFromLibraryName(first_name) + assert len(result1) + assert Path(result1).is_dir() + if alternative_name: + result2 = envvars.getFolderFromLibraryName(alternative_name) + assert result2 + assert result2 == result1 + + ## Quick access + # result = envvars.getFolderFromLibraryName('Quick access') # assert len(result) # assert Path(result).is_dir() - # result2 = ext.getFolderFromLibraryName('Snelle toegang') + # result2 = envvars.getFolderFromLibraryName('Snelle toegang') # assert result2 == result ## special cases: - home_folder = ext.getFolderFromLibraryName('~') - documents_folder = ext.getFolderFromLibraryName('Documents') - personal_folder = ext.getExtendedEnv('PERSONAL') + home_folder = envvars.getFolderFromLibraryName('~') + documents_folder = envvars.getFolderFromLibraryName('Documents') + personal_folder = envvars.getExtendedEnv('PERSONAL') assert documents_folder == personal_folder assert documents_folder.startswith(home_folder) - appdata_folder = ext.getFolderFromLibraryName('APPDATA') + appdata_folder = envvars.getFolderFromLibraryName('APPDATA') assert appdata_folder == str(Path(home_folder)/'AppData'/'Roaming') - local_appdata_folder = ext.getFolderFromLibraryName('LOCAL_APPDATA') + local_appdata_folder = envvars.getFolderFromLibraryName('LOCAL_APPDATA') assert local_appdata_folder.startswith(home_folder) - common_appdata_folder = ext.getFolderFromLibraryName('COMMON_APPDATA') + common_appdata_folder = envvars.getFolderFromLibraryName('COMMON_APPDATA') assert Path(common_appdata_folder).is_dir() # for lName in ['Snelle toegang', 'Quick access', 'Dropbox', 'OneDrive'']: # f = getFolderFromLibraryName(lName) +def main(): + pytest.main(["test_extenvvars.py"]) + if __name__ == "__main__": - pytest.main(['test_extenvvars.py']) + main() + \ No newline at end of file diff --git a/tests/test_inivars.py b/tests/test_inivars.py index 71fe5fa..96f83a1 100644 --- a/tests/test_inivars.py +++ b/tests/test_inivars.py @@ -11,13 +11,7 @@ # from dtactions.unimacro import unimacroinivars as inivars # old style from dtactions.unimacro import inivars -try: - from dtactions.__init__ import getThisDir, checkDirectory -except ModuleNotFoundError: - print('Run this module after "build_package" and "flit install --symlink"\n') - raise - -thisDir = getThisDir(__file__) +thisDir = Path(__file__).parent dtactionsDir = thisDir.parent testDir = Path(thisDir)/'test_inivarsfiles' diff --git a/tests/test_unimacroutils.py b/tests/test_unimacroutils.py index 4e4d972..4ecd49f 100644 --- a/tests/test_unimacroutils.py +++ b/tests/test_unimacroutils.py @@ -1,15 +1,21 @@ """ -This module tests the unimacro utils module +This module tests the unimacro utils module -Quintijn Hoogenboom, 2022 +Note: the important functions `getProgInfo` and `getModInfo` are using autohotkey (if installed) when +Dragon is not running, and the call to `natlink.getCurrentModule()` throws an error. + +Quintijn Hoogenboom, 2022/2024 """ +import sys import time from pathlib import Path import pytest import win32gui # from dtactions import natlinkclipboard # from dtactions.unimacro import unimacroinivars as inivars # old style +import natlink from dtactions.unimacro import unimacroutils +from dtactions import autohotkeyactions thisDir = Path(__file__).parent @@ -26,6 +32,7 @@ def test_classname(): assert isinstance(classname, str) assert len(classname) > 0 + def test_getProgInfo(): """testing the getProgInfo function """ @@ -33,8 +40,53 @@ def test_getProgInfo(): print(f'progInfo: {progInfo}') assert len(progInfo) == 6 assert isinstance(progInfo.hndle, int) + if natlink.isNatSpeakRunning(): + progInfoAhk = autohotkeyactions.getProgInfo() + assert progInfo == progInfoAhk + else: + print('test_getProgInfo: cannot test equal result of autohotkeyactions.getProgInfo, and via natlink.getModInfo, because Dragon is not running') + +def test_mouse_move(nat_conn): + """test moving the mouse, also with Dragon16 + """ + xp, yp = 500, 200 + unimacroutils.set_mouse_position(xp, yp) + xpn, ypn = unimacroutils.getMousePosition() + xpnl, ypnl = natlink.getCursorPos() + assert (xpnl, ypnl) == (xpn, ypn) + + assert (xp, yp) == (xpn, ypn) + +def test_getMousePositions(nat_conn): + """test the function which prints the mouse positions + """ + xp, yp = 500, 200 + unimacroutils.set_mouse_position(xp, yp) + absolute = 0 + result = unimacroutils.getMousePositions(absolute) + wrong_result = """ABSOLUTE MOUSE POSITIONS: +---related to WHOLE SCREEN: +top left: MP(0, 393, 153) +---related to ACTIVE WINDOW: +top left: MP(1, 400, 160) +---related to ACTIVE MONITOR: +top left: MP(3, 393, 153) +---related to CLIENT AREA: +top left: MP(5, 392, 160)""" + + assert result == wrong_result + +def test_myoutput(capsys, nat_conn): + print("hello") + sys.stderr.write("world\n") + captured = capsys.readouterr() + assert captured.out == "hello\n" + assert captured.err == "world\n" + print("next") + captured = capsys.readouterr() + assert captured.out == "next\n" if __name__ == "__main__": - pytest.main(['test_unimacroutils.py']) + pytest.main(['test_unimacroutils.py::test_getMousePositions']) diff --git a/tests/unittestAutohotkeyactions.py b/tests/unittestAutohotkeyactions.py index 52b75f4..8a71ae1 100644 --- a/tests/unittestAutohotkeyactions.py +++ b/tests/unittestAutohotkeyactions.py @@ -3,6 +3,11 @@ This module tests the actions, that are performed by autohotkey (autohotkeyactions) +Note: August 2024, this module sucks from many sides. Some AHK expert should delve into this... + +The autohotkeyactions module has as two important well working functions getProgInfo and getModInfo, +which give the wanted information also when Dragon is not running. + Quintijn Hoogenboom, 2021 """ import unittest