Commits

Anonymous committed 5b347ba

fix tests. The problem was that you cannot just try to activate() the first
window in the list, because it might be non-activable (e.g., the ubuntu
panel). Moreover, 10x20 is too small as a geometry, xclock might still be
slightly larger. If we use a bigger geometry, we get the exact values

Comments (0)

Files changed (1)

wmctrl/test_wmctrl.py

 import time
 from wmctrl import Window
 
-NAME='xclock-for-pytest'
+class Xchild(object):
+    cmd = None
+    ARGS = []
+    sleep = 0.1
 
-class get_xclock(object):
     def __init__(self, *args):
-        self.child = subprocess.Popen(['xclock', '-name', NAME]+list(args))
-        time.sleep(0.1)
+        arglist = [self.CMD, '-name', self.NAME] + list(args)
+        self.child = subprocess.Popen(arglist)
+        time.sleep(self.sleep)
 
     def __del__(self):
         self.child.kill()
 
-def get_win(*args):
-    xclock = get_xclock(*args)
-    win = Window.by_name(NAME)
-    return win[0], xclock
+class Apps:
+    class get_xclock(Xchild):
+        CMD = 'xclock'
+        NAME = 'xclock-for-pytest'
+
+    class get_xfontsel(Xchild):
+        CMD = 'xfontsel'
+        NAME = 'xfontsel-for-pytest'
+
+def get_win(name, *args):
+    get_app = getattr(Apps, 'get_%s' % name)        
+    xapp = get_app(*args)
+    win = Window.by_name(get_app.NAME)
+    return win[0], xapp
 
 def test_list():
-    xclock = get_xclock()
+    xclock = Apps.get_xclock()
     wins = Window.list()
     names = [win.wm_name for win in wins]
-    assert NAME in names
+    assert xclock.NAME in names
 
 def test_attributes():
-    win, xclock = get_win('-geometry', '100x200+0+0')
-    assert win.wm_name == NAME
-    assert win.wm_class == NAME + '.XClock'
+    win, xclock = get_win('xclock', '-geometry', '100x200+0+0')
+    assert win.wm_name == xclock.NAME
+    assert win.wm_class == xclock.NAME + '.XClock'
     assert win.w == 100
     assert win.h == 200
     # measure the width and the height of WM decorations
     ofs_x = win.x
     ofs_y = win.y
     xclock.child.kill()
-    win, xclock = get_win('-geometry', '+30+40')
+    win, xclock = get_win('xclock', '-geometry', '+30+40')
     assert win.x == 30 + ofs_x
     assert win.y == 40 + ofs_y
 
 def test_activate():
-    win = Window.list()
     orig = Window.get_active()
-    win[0].activate()
+    win, xfontsel = get_win('xfontsel', '-geometry', '+0+0')
+    win.activate()
+    time.sleep(0.5)
     active = Window.get_active()
-    assert active.id == win[0].id
+    assert active.id == win.id
     orig.activate()
+    time.sleep(0.5)
+    active = Window.get_active()
+    assert active.id == orig.id
 
 def test_resize_and_move():
-    win, xclock = get_win('-geometry', '+0+0')
+    win, xclock = get_win('xclock', '-geometry', '+0+0')
     ofs_x = win.x
     ofs_y = win.y
     win.resize_and_move(10, 20, 30, 40)
-    win2 = Window.by_name(NAME)[0]
+    win2 = Window.by_name(xclock.NAME)[0]
     assert win.id == win2.id
     assert win2.x == 10 + ofs_x
     assert win2.y == 20 + ofs_y
     assert win2.h == 40
 
 def check_geometry(geom):
-    win, xclock = get_win('-geometry', geom)
+    win, xclock = get_win('xclock', '-geometry', geom)
     win.resize_and_move(0, 0, 100, 200)
     win.set_geometry(geom)
-    win2 = Window.by_name(NAME)[0]
+    win2 = Window.by_name(xclock.NAME)[0]
     assert win2.x == win.x
     assert win2.y == win.y
     assert win2.w == win.w
     assert win2.h == win.h
 
 def test_geometry():
-    check_geometry('10x20+30+40')
+    check_geometry('100x200+30+40')
 
 def test_geometry_negative():
     py.test.skip('fixme')
-    check_geometry('10x20-30-40')
+    check_geometry('100x200-30-40')
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.