From e43a1120c052b836175658e56577dbcfae89402e Mon Sep 17 00:00:00 2001 From: Edgar Arakelyan Date: Thu, 19 Nov 2026 17:34:01 -0800 Subject: [PATCH] test(computers): the clock panel test reads the config a call left once it has seen the call The test's xfconf-query stand-in recorded each call before running it and wrote the panel's config in place, so a test that waited for a call and then read the config could read it truncated (JSONDecodeError, as unit (2/2) hit on #830) or as it was before the call. The stand-in now records a call, with when it began, once the call is done, and replaces the config whole. Co-Authored-By: Claude Opus 5.5 --- .../env/envs/test_computer_clock_panel.py | 42 ++++++++++--------- 1 file changed, 23 insertions(+), 19 deletions(-) diff --git a/tst/unit/env/envs/test_computer_clock_panel.py b/tst/unit/env/envs/test_computer_clock_panel.py index 1c4a0a85e..a89249ff0 100644 --- a/tst/unit/env/envs/test_computer_clock_panel.py +++ b/tst/unit/env/envs/test_computer_clock_panel.py @@ -28,27 +28,31 @@ "/plugins/plugin-13/style": "0", "/plugins/plugin-20": "clock", "/plugins/plugin-20/timezone": "Asia/Tokyo", "/plugins/plugin-22/base-directory": "/home/user"} #: xfconf-query on the panel's channel kept in a JSON file: it lists (``-l -v``), sets (``-s``) and resets (``-r``), -#: recording each call, and fails the next reset while the failure marker is there, removing it. +#: and fails the next reset while the failure marker is there, removing it. It records each call with when it began, +#: once the call is done, and replaces the file whole, so a test that has seen a call reads the config it left. XFCONF = """#!@PYTHON@ import json, os, sys, time -args = sys.argv[1:] -with open("@CALLS@", "a") as f: - f.write(json.dumps({"at": time.time(), "args": args}) + "\\n") -with open("@STATE@") as f: - state = json.load(f) -path = args[args.index("-p") + 1] -if "-l" in args: - sys.stdout.write("".join(f"{key:<36}{value}\\n" for key, value in sorted(state.items()))) - sys.exit(0) -if "-r" in args and os.path.exists("@FAIL@"): - os.remove("@FAIL@") - sys.exit("Failed to init libxfconf: the bus went away") -if "-r" in args: - state.pop(path, None) -else: - state[path] = args[args.index("-s") + 1] -with open("@STATE@", "w") as f: - json.dump(state, f) +args, at = sys.argv[1:], time.time() +try: + with open("@STATE@") as f: + state = json.load(f) + path = args[args.index("-p") + 1] + if "-l" in args: + sys.stdout.write("".join(f"{key:<36}{value}\\n" for key, value in sorted(state.items()))) + sys.exit(0) + if "-r" in args and os.path.exists("@FAIL@"): + os.remove("@FAIL@") + sys.exit("Failed to init libxfconf: the bus went away") + if "-r" in args: + state.pop(path, None) + else: + state[path] = args[args.index("-s") + 1] + with open("@STATE@.tmp", "w") as f: + json.dump(state, f) + os.replace("@STATE@.tmp", "@STATE@") +finally: + with open("@CALLS@", "a") as f: + f.write(json.dumps({"at": at, "args": args}) + "\\n") """ TIMEZONE = "/plugins/plugin-12/timezone" SET = ["-c", "xfce4-panel", "-p", TIMEZONE, "-n", "-t", "string", "-s", ZONE]