Skip to content

Commit

Permalink
raise when executable location not found
Browse files Browse the repository at this point in the history
  • Loading branch information
spyoungtech committed Dec 15, 2018
1 parent 86a3524 commit a1c5a91
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
4 changes: 3 additions & 1 deletion ahk/script.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,19 @@

logger = make_logger(__name__)


class ExecutableNotFoundError(EnvironmentError):
pass


class ScriptEngine(object):
def __init__(self, executable_path: str='', **kwargs):
"""
:param executable_path: the path to the AHK executable.
Defaults to environ['AHK_PATH'] if not explicitly provided
If environment variable not present, tries to look for 'AutoHotkey.exe' or 'AutoHotkeyA32.exe' with shutil.which
:param keep_scripts:
:raises RuntimeError: if AHK executable is not provided and cannot be found in environment variables or PATH
:raises ExecutableNotFound: if AHK executable is not provided and cannot be found in environment variables or PATH
"""
if not executable_path:
executable_path = os.environ.get('AHK_PATH') or which('AutoHotkey.exe') or which('AutoHotkeyA32.exe')
Expand Down
4 changes: 2 additions & 2 deletions tests/unittests/test_executable_location.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def check_pwd():

def test_no_executable_raises_error():
check_pwd()
with mock.patch.dict(os.environ, {'PATH': ''}):
with mock.patch.dict(os.environ, {'PATH': ''}, clear=True):
with pytest.raises(ExecutableNotFoundError):
AHK()

Expand All @@ -47,6 +47,6 @@ def test_executable_from_path():
check_pwd()
actual_path = AHK().executable_path
ahk_location = os.path.abspath(os.path.dirname(actual_path))
with mock.patch.dict(os.environ, {'PATH': ahk_location}):
with mock.patch.dict(os.environ, {'PATH': ahk_location}, clear=True):
ahk = AHK()
assert ahk.executable_path == actual_path

0 comments on commit a1c5a91

Please sign in to comment.