From 27f97953e06b3b9e7a4df4d43b26184db6a6625a Mon Sep 17 00:00:00 2001 From: Alyssa Ross Date: Wed, 22 Mar 2023 15:49:32 +0000 Subject: [PATCH] nixos/test-driver: accept non-\w* filenames What the code was trying to do was helpfully add a directory and extension if none were specified, but it did this by checking whether the filename was composed of a very limited character set that didn't even include dashes. With this change, the intention of the code is clearer, and I can put dashes in my screenshot names. --- nixos/lib/test-driver/test_driver/machine.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/nixos/lib/test-driver/test_driver/machine.py b/nixos/lib/test-driver/test_driver/machine.py index 4929f2048ecc..9de98c217a58 100644 --- a/nixos/lib/test-driver/test_driver/machine.py +++ b/nixos/lib/test-driver/test_driver/machine.py @@ -737,9 +737,10 @@ class Machine: self.connected = True def screenshot(self, filename: str) -> None: - word_pattern = re.compile(r"^\w+$") - if word_pattern.match(filename): - filename = os.path.join(self.out_dir, f"{filename}.png") + if "." not in filename: + filename += ".png" + if "/" not in filename: + filename = os.path.join(self.out_dir, filename) tmp = f"{filename}.ppm" with self.nested(