mirror of
https://github.com/ilyakooo0/nixpkgs.git
synced 2024-11-14 15:36:47 +03:00
nixosTests.keymap: Port to python
This commit is contained in:
parent
8f6f418e42
commit
5ae9820ea4
@ -3,14 +3,13 @@
|
|||||||
pkgs ? import ../.. { inherit system config; }
|
pkgs ? import ../.. { inherit system config; }
|
||||||
}:
|
}:
|
||||||
|
|
||||||
with import ../lib/testing.nix { inherit system pkgs; };
|
with import ../lib/testing-python.nix { inherit system pkgs; };
|
||||||
|
|
||||||
let
|
let
|
||||||
readyFile = "/tmp/readerReady";
|
readyFile = "/tmp/readerReady";
|
||||||
resultFile = "/tmp/readerResult";
|
resultFile = "/tmp/readerResult";
|
||||||
|
|
||||||
testReader = pkgs.writeScript "test-input-reader" ''
|
testReader = pkgs.writeScript "test-input-reader" ''
|
||||||
#!${pkgs.stdenv.shell}
|
|
||||||
rm -f ${resultFile} ${resultFile}.tmp
|
rm -f ${resultFile} ${resultFile}.tmp
|
||||||
logger "testReader: START: Waiting for $1 characters, expecting '$2'."
|
logger "testReader: START: Waiting for $1 characters, expecting '$2'."
|
||||||
touch ${readyFile}
|
touch ${readyFile}
|
||||||
@ -27,56 +26,75 @@ let
|
|||||||
'';
|
'';
|
||||||
|
|
||||||
|
|
||||||
mkKeyboardTest = layout: { extraConfig ? {}, tests }: with pkgs.lib; let
|
mkKeyboardTest = layout: { extraConfig ? {}, tests }: with pkgs.lib; makeTest {
|
||||||
combinedTests = foldAttrs (acc: val: acc ++ val) [] (builtins.attrValues tests);
|
|
||||||
perlStr = val: "'${escape ["'" "\\"] val}'";
|
|
||||||
lq = length combinedTests.qwerty;
|
|
||||||
le = length combinedTests.expect;
|
|
||||||
msg = "length mismatch between qwerty (${toString lq}) and expect (${toString le}) lists!";
|
|
||||||
send = concatMapStringsSep ", " perlStr combinedTests.qwerty;
|
|
||||||
expect = if (lq == le) then concatStrings combinedTests.expect else throw msg;
|
|
||||||
|
|
||||||
in makeTest {
|
|
||||||
name = "keymap-${layout}";
|
name = "keymap-${layout}";
|
||||||
|
|
||||||
|
machine.console.keyMap = mkOverride 900 layout;
|
||||||
machine.services.xserver.desktopManager.xterm.enable = false;
|
machine.services.xserver.desktopManager.xterm.enable = false;
|
||||||
machine.i18n.consoleKeyMap = mkOverride 900 layout;
|
|
||||||
machine.services.xserver.layout = mkOverride 900 layout;
|
machine.services.xserver.layout = mkOverride 900 layout;
|
||||||
machine.imports = [ ./common/x11.nix extraConfig ];
|
machine.imports = [ ./common/x11.nix extraConfig ];
|
||||||
|
|
||||||
testScript = ''
|
testScript = ''
|
||||||
|
import json
|
||||||
|
import shlex
|
||||||
|
|
||||||
sub mkTest ($$) {
|
|
||||||
my ($desc, $cmd) = @_;
|
|
||||||
|
|
||||||
subtest $desc, sub {
|
def run_test_case(cmd, xorg_keymap, test_case_name, inputs, expected):
|
||||||
# prepare and start testReader
|
with subtest(test_case_name):
|
||||||
$machine->execute("rm -f ${readyFile} ${resultFile}");
|
assert len(inputs) == len(expected)
|
||||||
$machine->succeed("$cmd ${testReader} ${toString le} ".q(${escapeShellArg expect} & ));
|
machine.execute("rm -f ${readyFile} ${resultFile}")
|
||||||
|
|
||||||
if ($desc eq "Xorg keymap") {
|
# set up process that expects all the keys to be entered
|
||||||
# make sure the xterm window is open and has focus
|
machine.succeed(
|
||||||
$machine->waitForWindow(qr/testterm/);
|
"{} {} {} {} &".format(
|
||||||
$machine->waitUntilSucceeds("${pkgs.xdotool}/bin/xdotool search --sync --onlyvisible --class testterm windowfocus --sync");
|
cmd,
|
||||||
}
|
"${testReader}",
|
||||||
|
len(inputs),
|
||||||
|
shlex.quote("".join(expected)),
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
# wait for reader to be ready
|
if xorg_keymap:
|
||||||
$machine->waitForFile("${readyFile}");
|
# make sure the xterm window is open and has focus
|
||||||
$machine->sleep(1);
|
machine.wait_for_window("testterm")
|
||||||
|
machine.wait_until_succeeds(
|
||||||
|
"${pkgs.xdotool}/bin/xdotool search --sync --onlyvisible "
|
||||||
|
"--class testterm windowfocus --sync"
|
||||||
|
)
|
||||||
|
|
||||||
# send all keys
|
# wait for reader to be ready
|
||||||
foreach ((${send})) { $machine->sendKeys($_); };
|
machine.wait_for_file("${readyFile}")
|
||||||
|
machine.sleep(1)
|
||||||
|
|
||||||
# wait for result and check
|
# send all keys
|
||||||
$machine->waitForFile("${resultFile}");
|
for key in inputs:
|
||||||
$machine->succeed("grep -q 'PASS:' ${resultFile}");
|
machine.send_key(key)
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
$machine->waitForX;
|
# wait for result and check
|
||||||
|
machine.wait_for_file("${resultFile}")
|
||||||
|
machine.succeed("grep -q 'PASS:' ${resultFile}")
|
||||||
|
|
||||||
mkTest "VT keymap", "openvt -sw --";
|
|
||||||
mkTest "Xorg keymap", "DISPLAY=:0 xterm -title testterm -class testterm -fullscreen -e";
|
with open("${pkgs.writeText "tests.json" (builtins.toJSON tests)}") as json_file:
|
||||||
|
tests = json.load(json_file)
|
||||||
|
|
||||||
|
keymap_environments = {
|
||||||
|
"VT Keymap": "openvt -sw --",
|
||||||
|
"Xorg Keymap": "DISPLAY=:0 xterm -title testterm -class testterm -fullscreen -e",
|
||||||
|
}
|
||||||
|
|
||||||
|
machine.wait_for_x()
|
||||||
|
|
||||||
|
for keymap_env_name, command in keymap_environments.items():
|
||||||
|
with subtest(keymap_env_name):
|
||||||
|
for test_case_name, test_data in tests.items():
|
||||||
|
run_test_case(
|
||||||
|
command,
|
||||||
|
False,
|
||||||
|
test_case_name,
|
||||||
|
test_data["qwerty"],
|
||||||
|
test_data["expect"],
|
||||||
|
)
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -89,7 +107,7 @@ in pkgs.lib.mapAttrs mkKeyboardTest {
|
|||||||
altgr.expect = [ "~" "#" "{" "[" "|" ];
|
altgr.expect = [ "~" "#" "{" "[" "|" ];
|
||||||
};
|
};
|
||||||
|
|
||||||
extraConfig.i18n.consoleKeyMap = "azerty/fr";
|
extraConfig.console.keyMap = "azerty/fr";
|
||||||
extraConfig.services.xserver.layout = "fr";
|
extraConfig.services.xserver.layout = "fr";
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -99,7 +117,7 @@ in pkgs.lib.mapAttrs mkKeyboardTest {
|
|||||||
homerow.expect = [ "a" "r" "s" "t" "n" "e" "i" "o" ];
|
homerow.expect = [ "a" "r" "s" "t" "n" "e" "i" "o" ];
|
||||||
};
|
};
|
||||||
|
|
||||||
extraConfig.i18n.consoleKeyMap = "colemak/colemak";
|
extraConfig.console.keyMap = "colemak/colemak";
|
||||||
extraConfig.services.xserver.layout = "us";
|
extraConfig.services.xserver.layout = "us";
|
||||||
extraConfig.services.xserver.xkbVariant = "colemak";
|
extraConfig.services.xserver.xkbVariant = "colemak";
|
||||||
};
|
};
|
||||||
@ -151,7 +169,7 @@ in pkgs.lib.mapAttrs mkKeyboardTest {
|
|||||||
altgr.expect = [ "@" "|" "{" "[" "]" "}" ];
|
altgr.expect = [ "@" "|" "{" "[" "]" "}" ];
|
||||||
};
|
};
|
||||||
|
|
||||||
extraConfig.i18n.consoleKeyMap = "de";
|
extraConfig.console.keyMap = "de";
|
||||||
extraConfig.services.xserver.layout = "de";
|
extraConfig.services.xserver.layout = "de";
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user