Merge pull request #174441 from tljuniper/172325-nixostest-override-python-pkgs-additional-param
nixos/test-driver: additional Python packages in test driver
This commit is contained in:
@@ -393,3 +393,25 @@ with foo_running:
|
|||||||
def foo_running():
|
def foo_running():
|
||||||
machine.succeed("pgrep -x foo")
|
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`.
|
||||||
|
|||||||
@@ -665,4 +665,30 @@ def foo_running():
|
|||||||
```
|
```
|
||||||
</programlisting>
|
</programlisting>
|
||||||
</section>
|
</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>
|
</section>
|
||||||
|
|||||||
@@ -10,6 +10,7 @@
|
|||||||
, socat
|
, socat
|
||||||
, tesseract4
|
, tesseract4
|
||||||
, vde2
|
, vde2
|
||||||
|
, extraPythonPackages ? (_ : [])
|
||||||
}:
|
}:
|
||||||
|
|
||||||
python3Packages.buildPythonApplication rec {
|
python3Packages.buildPythonApplication rec {
|
||||||
@@ -17,8 +18,17 @@ python3Packages.buildPythonApplication rec {
|
|||||||
version = "1.1";
|
version = "1.1";
|
||||||
src = ./.;
|
src = ./.;
|
||||||
|
|
||||||
propagatedBuildInputs = [ coreutils netpbm python3Packages.colorama python3Packages.ptpython qemu_pkg socat vde2 ]
|
propagatedBuildInputs = [
|
||||||
++ (lib.optionals enableOCR [ imagemagick_light tesseract4 ]);
|
coreutils
|
||||||
|
netpbm
|
||||||
|
python3Packages.colorama
|
||||||
|
python3Packages.ptpython
|
||||||
|
qemu_pkg
|
||||||
|
socat
|
||||||
|
vde2
|
||||||
|
]
|
||||||
|
++ (lib.optionals enableOCR [ imagemagick_light tesseract4 ])
|
||||||
|
++ extraPythonPackages python3Packages;
|
||||||
|
|
||||||
doCheck = true;
|
doCheck = true;
|
||||||
checkInputs = with python3Packages; [ mypy pylint black ];
|
checkInputs = with python3Packages; [ mypy pylint black ];
|
||||||
|
|||||||
@@ -53,12 +53,13 @@ rec {
|
|||||||
, skipTypeCheck ? false
|
, skipTypeCheck ? false
|
||||||
, passthru ? {}
|
, passthru ? {}
|
||||||
, interactive ? false
|
, interactive ? false
|
||||||
|
, extraPythonPackages ? (_ :[])
|
||||||
}:
|
}:
|
||||||
let
|
let
|
||||||
# Reifies and correctly wraps the python test driver for
|
# Reifies and correctly wraps the python test driver for
|
||||||
# the respective qemu version and with or without ocr support
|
# the respective qemu version and with or without ocr support
|
||||||
testDriver = pkgs.callPackage ./test-driver {
|
testDriver = pkgs.callPackage ./test-driver {
|
||||||
inherit enableOCR;
|
inherit enableOCR extraPythonPackages;
|
||||||
qemu_pkg = qemu_test;
|
qemu_pkg = qemu_test;
|
||||||
imagemagick_light = imagemagick_light.override { inherit libtiff; };
|
imagemagick_light = imagemagick_light.override { inherit libtiff; };
|
||||||
tesseract4 = tesseract4.override { enableLanguages = [ "eng" ]; };
|
tesseract4 = tesseract4.override { enableLanguages = [ "eng" ]; };
|
||||||
@@ -184,6 +185,7 @@ rec {
|
|||||||
(if meta.description or null != null
|
(if meta.description or null != null
|
||||||
then builtins.unsafeGetAttrPos "description" meta
|
then builtins.unsafeGetAttrPos "description" meta
|
||||||
else builtins.unsafeGetAttrPos "testScript" t)
|
else builtins.unsafeGetAttrPos "testScript" t)
|
||||||
|
, extraPythonPackages ? (_ : [])
|
||||||
} @ t:
|
} @ t:
|
||||||
let
|
let
|
||||||
mkNodes = qemu_pkg:
|
mkNodes = qemu_pkg:
|
||||||
@@ -236,13 +238,13 @@ rec {
|
|||||||
);
|
);
|
||||||
|
|
||||||
driver = setupDriverForTest {
|
driver = setupDriverForTest {
|
||||||
inherit testScript enableOCR skipTypeCheck skipLint passthru;
|
inherit testScript enableOCR skipTypeCheck skipLint passthru extraPythonPackages;
|
||||||
testName = name;
|
testName = name;
|
||||||
qemu_pkg = pkgs.qemu_test;
|
qemu_pkg = pkgs.qemu_test;
|
||||||
nodes = mkNodes pkgs.qemu_test;
|
nodes = mkNodes pkgs.qemu_test;
|
||||||
};
|
};
|
||||||
driverInteractive = setupDriverForTest {
|
driverInteractive = setupDriverForTest {
|
||||||
inherit testScript enableOCR skipTypeCheck skipLint passthru;
|
inherit testScript enableOCR skipTypeCheck skipLint passthru extraPythonPackages;
|
||||||
testName = name;
|
testName = name;
|
||||||
qemu_pkg = pkgs.qemu;
|
qemu_pkg = pkgs.qemu;
|
||||||
nodes = mkNodes pkgs.qemu;
|
nodes = mkNodes pkgs.qemu;
|
||||||
|
|||||||
@@ -166,6 +166,7 @@ let
|
|||||||
etcd-cluster = handleTestOn ["x86_64-linux"] ./etcd-cluster.nix {};
|
etcd-cluster = handleTestOn ["x86_64-linux"] ./etcd-cluster.nix {};
|
||||||
etebase-server = handleTest ./etebase-server.nix {};
|
etebase-server = handleTest ./etebase-server.nix {};
|
||||||
etesync-dav = handleTest ./etesync-dav.nix {};
|
etesync-dav = handleTest ./etesync-dav.nix {};
|
||||||
|
extra-python-packages = handleTest ./extra-python-packages.nix {};
|
||||||
fancontrol = handleTest ./fancontrol.nix {};
|
fancontrol = handleTest ./fancontrol.nix {};
|
||||||
fcitx = handleTest ./fcitx {};
|
fcitx = handleTest ./fcitx {};
|
||||||
fenics = handleTest ./fenics.nix {};
|
fenics = handleTest ./fenics.nix {};
|
||||||
|
|||||||
13
nixos/tests/extra-python-packages.nix
Normal file
13
nixos/tests/extra-python-packages.nix
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
import ./make-test-python.nix ({ ... }:
|
||||||
|
{
|
||||||
|
name = "extra-python-packages";
|
||||||
|
|
||||||
|
extraPythonPackages = p: [ p.numpy ];
|
||||||
|
|
||||||
|
nodes = { };
|
||||||
|
|
||||||
|
testScript = ''
|
||||||
|
import numpy as np
|
||||||
|
assert str(np.zeros(4) == "array([0., 0., 0., 0.])")
|
||||||
|
'';
|
||||||
|
})
|
||||||
Reference in New Issue
Block a user