Skip to content

Commit

Permalink
Use ProcessNotFoundError in connect(path='...') if timed out (for bac…
Browse files Browse the repository at this point in the history
…kward compatibility).
  • Loading branch information
vasily-v-ryabov committed Jul 3, 2017
1 parent 6d81a63 commit 184beb4
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
11 changes: 7 additions & 4 deletions pywinauto/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -930,10 +930,13 @@ def connect(self, **kwargs):
connected = True

elif 'path' in kwargs:
self.process = timings.wait_until_passes(
timeout, retry_interval, process_from_module,
ProcessNotFoundError, kwargs['path'],
)
try:
self.process = timings.wait_until_passes(
timeout, retry_interval, process_from_module,
ProcessNotFoundError, kwargs['path'],
)
except TimeoutError:
raise ProcessNotFoundError('Process "{}" not found!'.format(kwargs['path']))
connected = True

elif kwargs:
Expand Down
2 changes: 1 addition & 1 deletion pywinauto/unittests/test_application.py
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ def test_connect_raises(self):

# try to pass an invalid path
self.assertRaises(
TimeoutError,
ProcessNotFoundError,
Application().connect, **{'path': "no app here", 'timeout': 0.0})

def test_top_window(self):
Expand Down
12 changes: 6 additions & 6 deletions pywinauto/unittests/test_taskbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@
from pywinauto.application import WindowSpecification # noqa: E402
from pywinauto.sysinfo import is_x64_Python, is_x64_OS # noqa: E402
from pywinauto import win32defines # noqa: E402
from pywinauto.timings import WaitUntil # noqa: E402
from pywinauto.timings import wait_until # noqa: E402
import pywinauto.actionlogger # noqa: E402
from pywinauto.timings import Timings, TimeoutError # noqa: E402
from pywinauto.timings import Timings # noqa: E402
from pywinauto.controls.common_controls import ToolbarWrapper # noqa: E402
from pywinauto import mouse # noqa: E402
from pywinauto import Desktop # noqa: E402
Expand Down Expand Up @@ -80,7 +80,7 @@ def _cabinetwclass_exist():
l = findwindows.find_elements(active_only=True, class_name=class_name)
return (len(l) > 0)

WaitUntil(_ready_timeout, _retry_interval, _cabinetwclass_exist)
wait_until(_ready_timeout, _retry_interval, _cabinetwclass_exist)
handle = findwindows.find_elements(active_only=True,
class_name=class_name)[-1].handle
window = WindowSpecification({'handle': handle, 'backend': 'win32', })
Expand Down Expand Up @@ -147,7 +147,7 @@ def _wait_minimized(dlg):
wanted to make sure the dlg is really got to the 'minimized' state
because we test hiding the window to the tray.
"""
WaitUntil(
wait_until(
timeout=_ready_timeout,
retry_interval=_retry_interval,
func=lambda: (dlg.GetShowState() == win32defines.SW_SHOWMINIMIZED)
Expand Down Expand Up @@ -185,7 +185,7 @@ def tearDown(self):
app.connect(path="TrayMenu.exe")
l.log("Forse closing a leftover app: {0}".format(app))
app.kill_()
except(TimeoutError):
except(ProcessNotFoundError):
l.log("No more leftovers. All good.")

def testTaskbar(self):
Expand Down Expand Up @@ -262,7 +262,7 @@ def _show_popup_menu():
menu_window[0] = menu
return res

WaitUntil(self.tm, _retry_interval, _show_popup_menu)
wait_until(self.tm, _retry_interval, _show_popup_menu)
menu_window[0].MenuBarClickInput("#2", self.app)
popup_window = self.app.top_window()
hdl = self.dlg.PopupWindow()
Expand Down

0 comments on commit 184beb4

Please sign in to comment.