From 99d05b319f5da84eb7471e31508fc93fd9db69e8 Mon Sep 17 00:00:00 2001 From: tligui_y Date: Wed, 30 Jul 2025 11:47:48 +0200 Subject: [PATCH] Update tests/test_utils_termtitle.py --- tests/test_utils_termtitle.py | 61 ++++++++++++++++++++++++----------- 1 file changed, 43 insertions(+), 18 deletions(-) diff --git a/tests/test_utils_termtitle.py b/tests/test_utils_termtitle.py index c1be681e2..fdafb270e 100644 --- a/tests/test_utils_termtitle.py +++ b/tests/test_utils_termtitle.py @@ -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 - \ No newline at end of file + + # 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}'"