Skip to content

Commit b109526

Browse files
committed
tests: reduce some code duplication
Signed-off-by: Yuxuan Shui <[email protected]>
1 parent 323a59b commit b109526

File tree

3 files changed

+13
-33
lines changed

3 files changed

+13
-33
lines changed

tests/testcases/issue239.py

+3-9
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import xcffib.xproto as xproto
44
import xcffib
55
import time
6+
from common import set_window_name
67

78
conn = xcffib.connect()
89
setup = conn.get_setup()
@@ -18,13 +19,7 @@
1819
conn.core.CreateWindowChecked(depth, wid, root, 0, 0, 100, 100, 0, xproto.WindowClass.InputOutput, visual, 0, []).check()
1920

2021
# Set Window name so it doesn't get a shadow
21-
name = "_NET_WM_NAME"
22-
name_atom = conn.core.InternAtom(True, len(name), name).reply().atom
23-
str_type = "STRING"
24-
str_type_atom = conn.core.InternAtom(True, len(str_type), str_type).reply().atom
25-
26-
win_name = "NoShadow"
27-
conn.core.ChangePropertyChecked(xproto.PropMode.Replace, wid, name_atom, str_type_atom, 8, len(win_name), win_name).check()
22+
set_window_name(conn, wid, "NoShadow")
2823

2924
# Map the window
3025
print("mapping")
@@ -34,8 +29,7 @@
3429

3530
# Set the Window name so it gets a shadow
3631
print("set new name")
37-
win_name = "YesShadow"
38-
conn.core.ChangePropertyChecked(xproto.PropMode.Replace, wid, name_atom, str_type_atom, 8, len(win_name), win_name).check()
32+
set_window_name(conn, wid, "YesShadow")
3933

4034
# Unmap the window
4135
conn.core.UnmapWindowChecked(wid).check()

tests/testcases/issue239_3.py

+5-12
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import xcffib.xproto as xproto
44
import xcffib
55
import time
6+
from common import set_window_name
67

78
conn = xcffib.connect()
89
setup = conn.get_setup()
@@ -17,14 +18,8 @@
1718
# Create a window
1819
conn.core.CreateWindowChecked(depth, wid, root, 0, 0, 100, 100, 0, xproto.WindowClass.InputOutput, visual, 0, []).check()
1920

20-
# Set Window name so it doesn't get a shadow
21-
name = "_NET_WM_NAME"
22-
name_atom = conn.core.InternAtom(True, len(name), name).reply().atom
23-
str_type = "STRING"
24-
str_type_atom = conn.core.InternAtom(True, len(str_type), str_type).reply().atom
25-
26-
win_name = "YesShadow"
27-
conn.core.ChangePropertyChecked(xproto.PropMode.Replace, wid, name_atom, str_type_atom, 8, len(win_name), win_name).check()
21+
# Set Window name so it gets a shadow
22+
set_window_name(conn, wid, "YesShadow")
2823

2924
# Map the window
3025
print("mapping")
@@ -33,15 +28,13 @@
3328
time.sleep(0.5)
3429

3530
print("set new name")
36-
win_name = "NoShadow"
37-
conn.core.ChangePropertyChecked(xproto.PropMode.Replace, wid, name_atom, str_type_atom, 8, len(win_name), win_name).check()
31+
set_window_name(conn, wid, "NoShadow")
3832

3933
time.sleep(0.5)
4034

4135
# Set the Window name so it gets a shadow
4236
print("set new name")
43-
win_name = "YesShadow"
44-
conn.core.ChangePropertyChecked(xproto.PropMode.Replace, wid, name_atom, str_type_atom, 8, len(win_name), win_name).check()
37+
set_window_name(conn, wid, "YesShadow")
4538

4639
time.sleep(0.5)
4740

tests/testcases/issue239_3_norefresh.py

+5-12
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import xcffib.xproto as xproto
44
import xcffib
55
import time
6+
from common import set_window_name
67

78
conn = xcffib.connect()
89
setup = conn.get_setup()
@@ -17,14 +18,8 @@
1718
# Create a window
1819
conn.core.CreateWindowChecked(depth, wid, root, 0, 0, 100, 100, 0, xproto.WindowClass.InputOutput, visual, 0, []).check()
1920

20-
# Set Window name so it doesn't get a shadow
21-
name = "_NET_WM_NAME"
22-
name_atom = conn.core.InternAtom(True, len(name), name).reply().atom
23-
str_type = "STRING"
24-
str_type_atom = conn.core.InternAtom(True, len(str_type), str_type).reply().atom
25-
26-
win_name = "YesShadow"
27-
conn.core.ChangePropertyChecked(xproto.PropMode.Replace, wid, name_atom, str_type_atom, 8, len(win_name), win_name).check()
21+
# Set Window name so it gets a shadow
22+
set_window_name(conn, wid, "YesShadow")
2823

2924
# Map the window
3025
print("mapping")
@@ -33,13 +28,11 @@
3328
time.sleep(0.5)
3429

3530
print("set new name")
36-
win_name = "NoShadow"
37-
conn.core.ChangePropertyChecked(xproto.PropMode.Replace, wid, name_atom, str_type_atom, 8, len(win_name), win_name).check()
31+
set_window_name(conn, wid, "NoShadow")
3832

3933
# Set the Window name so it gets a shadow
4034
print("set new name")
41-
win_name = "YesShadow"
42-
conn.core.ChangePropertyChecked(xproto.PropMode.Replace, wid, name_atom, str_type_atom, 8, len(win_name), win_name).check()
35+
set_window_name(conn, wid, "YesShadow")
4336

4437
time.sleep(0.5)
4538

0 commit comments

Comments
 (0)