summary refs log tree commit diff
path: root/nixos/lib/testing-python.nix
blob: c303b0bf17bc057a66d9fa018f60416c19242a33 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
{ system
, pkgs ? import ../.. { inherit system config; }
  # Use a minimal kernel?
, minimal ? false
  # Ignored
, config ? { }
  # !!! See comment about args in lib/modules.nix
, specialArgs ? { }
  # Modules to add to each VM
, extraConfigurations ? [ ]
}:

with pkgs;

let
  nixos-lib = import ./default.nix { inherit (pkgs) lib; };
in

rec {

  inherit pkgs;

  evalTest = module: nixos-lib.evalTest { imports = [ extraTestModule module ]; };
  runTest = module: nixos-lib.runTest { imports = [ extraTestModule module ]; };

  extraTestModule = {
    config = {
      hostPkgs = pkgs;
    };
  };

  # Make a full-blown test
  makeTest =
    { machine ? null
    , nodes ? {}
    , testScript
    , enableOCR ? false
    , name ? "unnamed"
    , skipTypeCheck ? false
      # Skip linting (mainly intended for faster dev cycles)
    , skipLint ? false
    , passthru ? {}
    , meta ? {}
    , # For meta.position
      pos ? # position used in error messages and for meta.position
        (if meta.description or null != null
          then builtins.unsafeGetAttrPos "description" meta
          else builtins.unsafeGetAttrPos "testScript" t)
    , extraPythonPackages ? (_ : [])
    , interactive ? {}
    } @ t:
      runTest {
        imports = [
          { _file = "makeTest parameters"; config = t; }
          {
            defaults = {
              _file = "makeTest: extraConfigurations";
              imports = extraConfigurations;
            };
          }
        ];
      };

  simpleTest = as: (makeTest as).test;

}