diff options
author | Michael Schneider <michael.schneider@cyberus-technology.de> | 2022-06-02 09:58:46 +0200 |
---|---|---|
committer | Michael Schneider <michael.schneider@cyberus-technology.de> | 2022-06-02 10:05:45 +0200 |
commit | 814027378bcddb1f885a1a17f0b34b16d7593b54 (patch) | |
tree | 82176a0addf9bbafc0514659fe9554cfbfd9b503 /nixos/lib/testing-python.nix | |
parent | 3aeea3eb805bb95b4a6dcad7319f8a992276f6bb (diff) | |
download | nixpkgs-814027378bcddb1f885a1a17f0b34b16d7593b54.tar nixpkgs-814027378bcddb1f885a1a17f0b34b16d7593b54.tar.gz nixpkgs-814027378bcddb1f885a1a17f0b34b16d7593b54.tar.bz2 nixpkgs-814027378bcddb1f885a1a17f0b34b16d7593b54.tar.lz nixpkgs-814027378bcddb1f885a1a17f0b34b16d7593b54.tar.xz nixpkgs-814027378bcddb1f885a1a17f0b34b16d7593b54.tar.zst nixpkgs-814027378bcddb1f885a1a17f0b34b16d7593b54.zip |
nixos/test-driver: Typecheck TestScript
Diffstat (limited to 'nixos/lib/testing-python.nix')
-rw-r--r-- | nixos/lib/testing-python.nix | 25 |
1 files changed, 22 insertions, 3 deletions
diff --git a/nixos/lib/testing-python.nix b/nixos/lib/testing-python.nix index c1015ec0aca..b76ce3bc322 100644 --- a/nixos/lib/testing-python.nix +++ b/nixos/lib/testing-python.nix @@ -85,7 +85,7 @@ rec { nodeHostNames = let nodesList = map (c: c.config.system.name) (lib.attrValues nodes); - in nodesList ++ lib.optional (lib.length nodesList == 1) "machine"; + in nodesList ++ lib.optional (lib.length nodesList == 1 && !lib.elem "machine" nodesList) "machine"; # TODO: This is an implementation error and needs fixing # the testing famework cannot legitimately restrict hostnames further @@ -100,6 +100,9 @@ rec { then testScript { inherit nodes; } else testScript; + uniqueVlans = lib.unique (builtins.concatLists vlans); + vlanNames = map (i: "vlan${toString i}: VLan;") uniqueVlans; + machineNames = map (name: "${name}: Machine;") nodeHostNames; in if lib.length invalidNodeNames > 0 then throw '' @@ -113,7 +116,7 @@ rec { else lib.warnIf skipLint "Linting is disabled" (runCommand testDriverName { inherit testName; - nativeBuildInputs = [ makeWrapper ]; + nativeBuildInputs = [ makeWrapper mypy ]; testScript = testScript'; preferLocalBuild = true; passthru = passthru // { @@ -125,7 +128,23 @@ rec { mkdir -p $out/bin vmStartScripts=($(for i in ${toString vms}; do echo $i/bin/run-*-vm; done)) - echo -n "$testScript" > $out/test-script + + # prepend type hints so the test script can be type checked with mypy + cat "${./test-script-prepend.py}" >> testScriptWithTypes + echo "${builtins.toString machineNames}" >> testScriptWithTypes + echo "${builtins.toString vlanNames}" >> testScriptWithTypes + echo -n "$testScript" >> testScriptWithTypes + + # set pythonpath so mypy knows where to find the imports. this requires the py.typed file. + export PYTHONPATH='${./test-driver}' + mypy --no-implicit-optional \ + --pretty \ + --no-color-output \ + testScriptWithTypes + unset PYTHONPATH + + echo -n "$testScript" >> $out/test-script + ln -s ${testDriver}/bin/nixos-test-driver $out/bin/nixos-test-driver ${testDriver}/bin/generate-driver-symbols |