54 lines
1.6 KiB
Python
54 lines
1.6 KiB
Python
import pytest
|
|
import sys
|
|
import os
|
|
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
|
|
from slic.utils.termtitle import *
|
|
import subprocess
|
|
import time
|
|
|
|
import subprocess
|
|
import time
|
|
import pytest
|
|
|
|
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
|
|
)
|
|
|
|
# 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}'"
|