From 290a4cac51cda896d227f91bab8ab117866742bf Mon Sep 17 00:00:00 2001 From: Spencer Young Date: Thu, 13 Dec 2018 02:38:56 -0800 Subject: [PATCH] window tests --- tests/unittests/test_win_get.py | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/tests/unittests/test_win_get.py b/tests/unittests/test_win_get.py index b0d70707..81b2d05f 100644 --- a/tests/unittests/test_win_get.py +++ b/tests/unittests/test_win_get.py @@ -4,12 +4,34 @@ project_root = os.path.abspath(os.path.join(os.path.dirname(os.path.abspath(__file__)), '../..')) sys.path.insert(0, project_root) from ahk import AHK +from ahk.window import WindowNotFoundError +import pytest import subprocess ahk = AHK() def test_get_calculator(): - with subprocess.Popen('calc') as p: - time.sleep(2) # give calculator some time to start up; may replace this once WinWait is implemented - win = ahk.win_get(title='Calculator') + p = None + try: + p = subprocess.Popen('notepad') + time.sleep(1) # give notepad time to start up + win = ahk.win_get(title='Untitled - Notepad') assert win assert win.position + finally: + if p is not None: + p.terminate() + +def test_win_close(): + p = None + try: + p = subprocess.Popen('notepad') + time.sleep(1) # give notepad time to start up + win = ahk.win_get(title='Untitled - Notepad') + assert win + assert win.position + win.close() + with pytest.raises(WindowNotFoundError): + ahk.win_get(title='Untitled - Notepad').position + finally: + if p is not None: + p.terminate()