Loading nixos/doc/manual/development/writing-nixos-tests.section.md +22 −0 Original line number Diff line number Diff line Loading @@ -393,3 +393,25 @@ with foo_running: def foo_running(): machine.succeed("pgrep -x foo") ``` ## Adding Python packages to the test script {#ssec-python-packages-in-test-script} When additional Python libraries are required in the test script, they can be added using the parameter `extraPythonPackages`. For example, you could add `numpy` like this: ```nix import ./make-test-python.nix { extraPythonPackages = p: [ p.numpy ]; nodes = { }; testScript = '' import numpy as np assert str(np.zeros(4) == "array([0., 0., 0., 0.])") ''; } ``` In that case, `numpy` is chosen from the generic `python3Packages`. nixos/doc/manual/from_md/development/writing-nixos-tests.section.xml +26 −0 Original line number Diff line number Diff line Loading @@ -665,4 +665,30 @@ def foo_running(): ``` </programlisting> </section> <section xml:id="ssec-python-packages-in-test-script"> <title>Adding Python packages to the test script</title> <para> When additional Python libraries are required in the test script, they can be added using the parameter <literal>extraPythonPackages</literal>. For example, you could add <literal>numpy</literal> like this: </para> <programlisting language="bash"> import ./make-test-python.nix { extraPythonPackages = p: [ p.numpy ]; nodes = { }; testScript = '' import numpy as np assert str(np.zeros(4) == "array([0., 0., 0., 0.])") ''; } </programlisting> <para> In that case, <literal>numpy</literal> is chosen from the generic <literal>python3Packages</literal>. </para> </section> </section> nixos/lib/test-driver/default.nix +12 −2 Original line number Diff line number Diff line Loading @@ -10,6 +10,7 @@ , socat , tesseract4 , vde2 , extraPythonPackages ? (_ : []) }: python3Packages.buildPythonApplication rec { Loading @@ -17,8 +18,17 @@ python3Packages.buildPythonApplication rec { version = "1.1"; src = ./.; propagatedBuildInputs = [ coreutils netpbm python3Packages.colorama python3Packages.ptpython qemu_pkg socat vde2 ] ++ (lib.optionals enableOCR [ imagemagick_light tesseract4 ]); propagatedBuildInputs = [ coreutils netpbm python3Packages.colorama python3Packages.ptpython qemu_pkg socat vde2 ] ++ (lib.optionals enableOCR [ imagemagick_light tesseract4 ]) ++ extraPythonPackages python3Packages; doCheck = true; checkInputs = with python3Packages; [ mypy pylint black ]; Loading nixos/lib/testing-python.nix +5 −3 Original line number Diff line number Diff line Loading @@ -53,12 +53,13 @@ rec { , skipTypeCheck ? false , passthru ? {} , interactive ? false , extraPythonPackages ? (_ :[]) }: let # Reifies and correctly wraps the python test driver for # the respective qemu version and with or without ocr support testDriver = pkgs.callPackage ./test-driver { inherit enableOCR; inherit enableOCR extraPythonPackages; qemu_pkg = qemu_test; imagemagick_light = imagemagick_light.override { inherit libtiff; }; tesseract4 = tesseract4.override { enableLanguages = [ "eng" ]; }; Loading Loading @@ -184,6 +185,7 @@ rec { (if meta.description or null != null then builtins.unsafeGetAttrPos "description" meta else builtins.unsafeGetAttrPos "testScript" t) , extraPythonPackages ? (_ : []) } @ t: let mkNodes = qemu_pkg: Loading Loading @@ -236,13 +238,13 @@ rec { ); driver = setupDriverForTest { inherit testScript enableOCR skipTypeCheck skipLint passthru; inherit testScript enableOCR skipTypeCheck skipLint passthru extraPythonPackages; testName = name; qemu_pkg = pkgs.qemu_test; nodes = mkNodes pkgs.qemu_test; }; driverInteractive = setupDriverForTest { inherit testScript enableOCR skipTypeCheck skipLint passthru; inherit testScript enableOCR skipTypeCheck skipLint passthru extraPythonPackages; testName = name; qemu_pkg = pkgs.qemu; nodes = mkNodes pkgs.qemu; Loading nixos/modules/services/misc/uhub.nix +9 −5 Original line number Diff line number Diff line Loading @@ -80,11 +80,12 @@ in { tls_enable = cfg.enableTLS; file_plugins = pkgs.writeText "uhub-plugins.conf" (lib.strings.concatStringsSep "\n" (map ({ plugin, settings }: "plugin ${plugin} ${ '' plugin ${plugin} "${ toString (lib.attrsets.mapAttrsToList (key: value: ''"${key}=${value}"'') (lib.attrsets.mapAttrsToList (key: value: "${key}=${value}") settings) }") cfg.plugins)); }"'') cfg.plugins)); }; in { name = "uhub/${name}.conf"; Loading @@ -104,6 +105,9 @@ in { ExecStart = "${pkg}/bin/uhub -c /etc/uhub/${name}.conf -L"; ExecReload = "${pkgs.coreutils}/bin/kill -HUP $MAINPID"; DynamicUser = true; AmbientCapabilities = "CAP_NET_BIND_SERVICE"; CapabilityBoundingSet = "CAP_NET_BIND_SERVICE"; }; }; }) hubs; Loading Loading
nixos/doc/manual/development/writing-nixos-tests.section.md +22 −0 Original line number Diff line number Diff line Loading @@ -393,3 +393,25 @@ with foo_running: def foo_running(): machine.succeed("pgrep -x foo") ``` ## Adding Python packages to the test script {#ssec-python-packages-in-test-script} When additional Python libraries are required in the test script, they can be added using the parameter `extraPythonPackages`. For example, you could add `numpy` like this: ```nix import ./make-test-python.nix { extraPythonPackages = p: [ p.numpy ]; nodes = { }; testScript = '' import numpy as np assert str(np.zeros(4) == "array([0., 0., 0., 0.])") ''; } ``` In that case, `numpy` is chosen from the generic `python3Packages`.
nixos/doc/manual/from_md/development/writing-nixos-tests.section.xml +26 −0 Original line number Diff line number Diff line Loading @@ -665,4 +665,30 @@ def foo_running(): ``` </programlisting> </section> <section xml:id="ssec-python-packages-in-test-script"> <title>Adding Python packages to the test script</title> <para> When additional Python libraries are required in the test script, they can be added using the parameter <literal>extraPythonPackages</literal>. For example, you could add <literal>numpy</literal> like this: </para> <programlisting language="bash"> import ./make-test-python.nix { extraPythonPackages = p: [ p.numpy ]; nodes = { }; testScript = '' import numpy as np assert str(np.zeros(4) == "array([0., 0., 0., 0.])") ''; } </programlisting> <para> In that case, <literal>numpy</literal> is chosen from the generic <literal>python3Packages</literal>. </para> </section> </section>
nixos/lib/test-driver/default.nix +12 −2 Original line number Diff line number Diff line Loading @@ -10,6 +10,7 @@ , socat , tesseract4 , vde2 , extraPythonPackages ? (_ : []) }: python3Packages.buildPythonApplication rec { Loading @@ -17,8 +18,17 @@ python3Packages.buildPythonApplication rec { version = "1.1"; src = ./.; propagatedBuildInputs = [ coreutils netpbm python3Packages.colorama python3Packages.ptpython qemu_pkg socat vde2 ] ++ (lib.optionals enableOCR [ imagemagick_light tesseract4 ]); propagatedBuildInputs = [ coreutils netpbm python3Packages.colorama python3Packages.ptpython qemu_pkg socat vde2 ] ++ (lib.optionals enableOCR [ imagemagick_light tesseract4 ]) ++ extraPythonPackages python3Packages; doCheck = true; checkInputs = with python3Packages; [ mypy pylint black ]; Loading
nixos/lib/testing-python.nix +5 −3 Original line number Diff line number Diff line Loading @@ -53,12 +53,13 @@ rec { , skipTypeCheck ? false , passthru ? {} , interactive ? false , extraPythonPackages ? (_ :[]) }: let # Reifies and correctly wraps the python test driver for # the respective qemu version and with or without ocr support testDriver = pkgs.callPackage ./test-driver { inherit enableOCR; inherit enableOCR extraPythonPackages; qemu_pkg = qemu_test; imagemagick_light = imagemagick_light.override { inherit libtiff; }; tesseract4 = tesseract4.override { enableLanguages = [ "eng" ]; }; Loading Loading @@ -184,6 +185,7 @@ rec { (if meta.description or null != null then builtins.unsafeGetAttrPos "description" meta else builtins.unsafeGetAttrPos "testScript" t) , extraPythonPackages ? (_ : []) } @ t: let mkNodes = qemu_pkg: Loading Loading @@ -236,13 +238,13 @@ rec { ); driver = setupDriverForTest { inherit testScript enableOCR skipTypeCheck skipLint passthru; inherit testScript enableOCR skipTypeCheck skipLint passthru extraPythonPackages; testName = name; qemu_pkg = pkgs.qemu_test; nodes = mkNodes pkgs.qemu_test; }; driverInteractive = setupDriverForTest { inherit testScript enableOCR skipTypeCheck skipLint passthru; inherit testScript enableOCR skipTypeCheck skipLint passthru extraPythonPackages; testName = name; qemu_pkg = pkgs.qemu; nodes = mkNodes pkgs.qemu; Loading
nixos/modules/services/misc/uhub.nix +9 −5 Original line number Diff line number Diff line Loading @@ -80,11 +80,12 @@ in { tls_enable = cfg.enableTLS; file_plugins = pkgs.writeText "uhub-plugins.conf" (lib.strings.concatStringsSep "\n" (map ({ plugin, settings }: "plugin ${plugin} ${ '' plugin ${plugin} "${ toString (lib.attrsets.mapAttrsToList (key: value: ''"${key}=${value}"'') (lib.attrsets.mapAttrsToList (key: value: "${key}=${value}") settings) }") cfg.plugins)); }"'') cfg.plugins)); }; in { name = "uhub/${name}.conf"; Loading @@ -104,6 +105,9 @@ in { ExecStart = "${pkg}/bin/uhub -c /etc/uhub/${name}.conf -L"; ExecReload = "${pkgs.coreutils}/bin/kill -HUP $MAINPID"; DynamicUser = true; AmbientCapabilities = "CAP_NET_BIND_SERVICE"; CapabilityBoundingSet = "CAP_NET_BIND_SERVICE"; }; }; }) hubs; Loading