lol

Merge pull request #174441 from tljuniper/172325-nixostest-override-python-pkgs-additional-param

nixos/test-driver: additional Python packages in test driver

authored by

Robert Hensing and committed by
GitHub
bad676c7 b03fed42

+79 -5
+22
nixos/doc/manual/development/writing-nixos-tests.section.md
··· 393 393 def foo_running(): 394 394 machine.succeed("pgrep -x foo") 395 395 ``` 396 + 397 + ## Adding Python packages to the test script {#ssec-python-packages-in-test-script} 398 + 399 + When additional Python libraries are required in the test script, they can be 400 + added using the parameter `extraPythonPackages`. For example, you could add 401 + `numpy` like this: 402 + 403 + ```nix 404 + import ./make-test-python.nix 405 + { 406 + extraPythonPackages = p: [ p.numpy ]; 407 + 408 + nodes = { }; 409 + 410 + testScript = '' 411 + import numpy as np 412 + assert str(np.zeros(4) == "array([0., 0., 0., 0.])") 413 + ''; 414 + } 415 + ``` 416 + 417 + In that case, `numpy` is chosen from the generic `python3Packages`.
+26
nixos/doc/manual/from_md/development/writing-nixos-tests.section.xml
··· 665 665 ``` 666 666 </programlisting> 667 667 </section> 668 + <section xml:id="ssec-python-packages-in-test-script"> 669 + <title>Adding Python packages to the test script</title> 670 + <para> 671 + When additional Python libraries are required in the test script, 672 + they can be added using the parameter 673 + <literal>extraPythonPackages</literal>. For example, you could add 674 + <literal>numpy</literal> like this: 675 + </para> 676 + <programlisting language="bash"> 677 + import ./make-test-python.nix 678 + { 679 + extraPythonPackages = p: [ p.numpy ]; 680 + 681 + nodes = { }; 682 + 683 + testScript = '' 684 + import numpy as np 685 + assert str(np.zeros(4) == &quot;array([0., 0., 0., 0.])&quot;) 686 + ''; 687 + } 688 + </programlisting> 689 + <para> 690 + In that case, <literal>numpy</literal> is chosen from the generic 691 + <literal>python3Packages</literal>. 692 + </para> 693 + </section> 668 694 </section>
+12 -2
nixos/lib/test-driver/default.nix
··· 10 10 , socat 11 11 , tesseract4 12 12 , vde2 13 + , extraPythonPackages ? (_ : []) 13 14 }: 14 15 15 16 python3Packages.buildPythonApplication rec { ··· 17 18 version = "1.1"; 18 19 src = ./.; 19 20 20 - propagatedBuildInputs = [ coreutils netpbm python3Packages.colorama python3Packages.ptpython qemu_pkg socat vde2 ] 21 - ++ (lib.optionals enableOCR [ imagemagick_light tesseract4 ]); 21 + propagatedBuildInputs = [ 22 + coreutils 23 + netpbm 24 + python3Packages.colorama 25 + python3Packages.ptpython 26 + qemu_pkg 27 + socat 28 + vde2 29 + ] 30 + ++ (lib.optionals enableOCR [ imagemagick_light tesseract4 ]) 31 + ++ extraPythonPackages python3Packages; 22 32 23 33 doCheck = true; 24 34 checkInputs = with python3Packages; [ mypy pylint black ];
+5 -3
nixos/lib/testing-python.nix
··· 53 53 , skipTypeCheck ? false 54 54 , passthru ? {} 55 55 , interactive ? false 56 + , extraPythonPackages ? (_ :[]) 56 57 }: 57 58 let 58 59 # Reifies and correctly wraps the python test driver for 59 60 # the respective qemu version and with or without ocr support 60 61 testDriver = pkgs.callPackage ./test-driver { 61 - inherit enableOCR; 62 + inherit enableOCR extraPythonPackages; 62 63 qemu_pkg = qemu_test; 63 64 imagemagick_light = imagemagick_light.override { inherit libtiff; }; 64 65 tesseract4 = tesseract4.override { enableLanguages = [ "eng" ]; }; ··· 184 185 (if meta.description or null != null 185 186 then builtins.unsafeGetAttrPos "description" meta 186 187 else builtins.unsafeGetAttrPos "testScript" t) 188 + , extraPythonPackages ? (_ : []) 187 189 } @ t: 188 190 let 189 191 mkNodes = qemu_pkg: ··· 236 238 ); 237 239 238 240 driver = setupDriverForTest { 239 - inherit testScript enableOCR skipTypeCheck skipLint passthru; 241 + inherit testScript enableOCR skipTypeCheck skipLint passthru extraPythonPackages; 240 242 testName = name; 241 243 qemu_pkg = pkgs.qemu_test; 242 244 nodes = mkNodes pkgs.qemu_test; 243 245 }; 244 246 driverInteractive = setupDriverForTest { 245 - inherit testScript enableOCR skipTypeCheck skipLint passthru; 247 + inherit testScript enableOCR skipTypeCheck skipLint passthru extraPythonPackages; 246 248 testName = name; 247 249 qemu_pkg = pkgs.qemu; 248 250 nodes = mkNodes pkgs.qemu;
+1
nixos/tests/all-tests.nix
··· 166 166 etcd-cluster = handleTestOn ["x86_64-linux"] ./etcd-cluster.nix {}; 167 167 etebase-server = handleTest ./etebase-server.nix {}; 168 168 etesync-dav = handleTest ./etesync-dav.nix {}; 169 + extra-python-packages = handleTest ./extra-python-packages.nix {}; 169 170 fancontrol = handleTest ./fancontrol.nix {}; 170 171 fcitx = handleTest ./fcitx {}; 171 172 fenics = handleTest ./fenics.nix {};
+13
nixos/tests/extra-python-packages.nix
··· 1 + import ./make-test-python.nix ({ ... }: 2 + { 3 + name = "extra-python-packages"; 4 + 5 + extraPythonPackages = p: [ p.numpy ]; 6 + 7 + nodes = { }; 8 + 9 + testScript = '' 10 + import numpy as np 11 + assert str(np.zeros(4) == "array([0., 0., 0., 0.])") 12 + ''; 13 + })