This commit is contained in:
@@ -6,23 +6,48 @@ from slic.utils.termtitle import *
|
||||
import subprocess
|
||||
import time
|
||||
|
||||
@pytest.mark.skipif(not os.environ.get("WINDOWID"), reason="X11 actif terminal necessary")
|
||||
def test_termtitle_changes_actual_title():
|
||||
import subprocess
|
||||
import time
|
||||
import pytest
|
||||
|
||||
# Generate title
|
||||
test_title = f"TEST_{time.time()}"
|
||||
|
||||
# Change terminal title
|
||||
termtitle(test_title)
|
||||
time.sleep(0.5)
|
||||
|
||||
# Capture actual terminal title with xprop
|
||||
result = subprocess.run(
|
||||
["Xvfb", "-id", os.environ["WINDOWID"]],
|
||||
capture_output=True,
|
||||
text=True
|
||||
def test_terminal_title_via_xterm():
|
||||
expected_title = f"TITLE_TEST_{int(time.time())}"
|
||||
|
||||
# Lancer xterm avec un titre spécifique
|
||||
proc = subprocess.Popen(
|
||||
["xterm", "-T", expected_title, "-e", "sleep", "5"],
|
||||
stdout=subprocess.DEVNULL,
|
||||
stderr=subprocess.DEVNULL
|
||||
)
|
||||
captured_title = result.stdout.split("WM_NAME = ")[1].strip('"\n')
|
||||
|
||||
assert test_title in captured_title
|
||||
|
||||
|
||||
# Attendre que la fenêtre apparaisse
|
||||
time.sleep(1)
|
||||
|
||||
# Récupérer le WINDOWID avec xdotool
|
||||
try:
|
||||
window_id = subprocess.check_output(
|
||||
["xdotool", "search", "--name", expected_title],
|
||||
text=True
|
||||
).splitlines()[0].strip()
|
||||
except subprocess.CalledProcessError:
|
||||
proc.kill()
|
||||
pytest.fail("Could not find xterm window with expected title")
|
||||
|
||||
# Lire le titre de la fenêtre avec xprop
|
||||
try:
|
||||
xprop_output = subprocess.check_output(["xprop", "-id", window_id], text=True)
|
||||
except subprocess.CalledProcessError:
|
||||
proc.kill()
|
||||
pytest.fail("xprop failed on found window")
|
||||
|
||||
proc.terminate() # Fermer le xterm
|
||||
|
||||
# Extraire le titre réel
|
||||
for line in xprop_output.splitlines():
|
||||
if "WM_NAME(STRING)" in line or "WM_NAME(UTF8_STRING)" in line:
|
||||
actual_title = line.split("=", 1)[1].strip().strip('"')
|
||||
break
|
||||
else:
|
||||
pytest.fail("No WM_NAME found in xprop output")
|
||||
|
||||
assert expected_title == actual_title, f"Expected '{expected_title}', got '{actual_title}'"
|
||||
|
||||
Reference in New Issue
Block a user