mirror of
https://github.com/nix-community/dream2nix.git
synced 2024-11-23 00:13:02 +03:00
tests: add nix unit tests for pip module
This commit is contained in:
parent
678272fa4e
commit
4663912a1c
68
flake.lock
68
flake.lock
@ -70,6 +70,52 @@
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"nix-github-actions": {
|
||||
"inputs": {
|
||||
"nixpkgs": [
|
||||
"nix-unit",
|
||||
"nixpkgs"
|
||||
]
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1688870561,
|
||||
"narHash": "sha256-4UYkifnPEw1nAzqqPOTL2MvWtm3sNGw1UTYTalkTcGY=",
|
||||
"owner": "nix-community",
|
||||
"repo": "nix-github-actions",
|
||||
"rev": "165b1650b753316aa7f1787f3005a8d2da0f5301",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "nix-community",
|
||||
"repo": "nix-github-actions",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"nix-unit": {
|
||||
"inputs": {
|
||||
"flake-parts": [
|
||||
"flake-parts"
|
||||
],
|
||||
"nix-github-actions": "nix-github-actions",
|
||||
"nixpkgs": [
|
||||
"nixpkgs"
|
||||
],
|
||||
"treefmt-nix": "treefmt-nix"
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1690289081,
|
||||
"narHash": "sha256-PCXQAQt8+i2pkUym9P1JY4JGoeZJLzzxWBhprHDdItM=",
|
||||
"owner": "adisbladis",
|
||||
"repo": "nix-unit",
|
||||
"rev": "a9d6f33e50d4dcd9cfc0c92253340437bbae282b",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "adisbladis",
|
||||
"repo": "nix-unit",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"nixpkgs": {
|
||||
"locked": {
|
||||
"lastModified": 1686501370,
|
||||
@ -111,6 +157,7 @@
|
||||
"devshell": "devshell",
|
||||
"flake-compat": "flake-compat",
|
||||
"flake-parts": "flake-parts",
|
||||
"nix-unit": "nix-unit",
|
||||
"nixpkgs": "nixpkgs",
|
||||
"pre-commit-hooks": "pre-commit-hooks"
|
||||
}
|
||||
@ -129,6 +176,27 @@
|
||||
"repo": "default",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"treefmt-nix": {
|
||||
"inputs": {
|
||||
"nixpkgs": [
|
||||
"nix-unit",
|
||||
"nixpkgs"
|
||||
]
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1689620039,
|
||||
"narHash": "sha256-BtNwghr05z7k5YMdq+6nbue+nEalvDepuA7qdQMAKoQ=",
|
||||
"owner": "numtide",
|
||||
"repo": "treefmt-nix",
|
||||
"rev": "719c2977f958c41fa60a928e2fbc50af14844114",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "numtide",
|
||||
"repo": "treefmt-nix",
|
||||
"type": "github"
|
||||
}
|
||||
}
|
||||
},
|
||||
"root": "root",
|
||||
|
@ -18,6 +18,10 @@
|
||||
pre-commit-hooks.url = "github:cachix/pre-commit-hooks.nix";
|
||||
pre-commit-hooks.inputs.nixpkgs.follows = "nixpkgs";
|
||||
|
||||
nix-unit.url = "github:adisbladis/nix-unit";
|
||||
nix-unit.inputs.nixpkgs.follows = "nixpkgs";
|
||||
nix-unit.inputs.flake-parts.follows = "flake-parts";
|
||||
|
||||
devshell = {
|
||||
url = "github:numtide/devshell";
|
||||
flake = false;
|
||||
@ -40,6 +44,7 @@
|
||||
config,
|
||||
pkgs,
|
||||
system,
|
||||
inputs',
|
||||
...
|
||||
}: {
|
||||
apps = {
|
||||
@ -78,6 +83,7 @@
|
||||
packages = [
|
||||
pkgs.alejandra
|
||||
pkgs.mdbook
|
||||
inputs'.nix-unit.packages.nix-unit
|
||||
(pkgs.python3.withPackages (ps: [
|
||||
pkgs.python3.pkgs.black
|
||||
]))
|
||||
|
17
modules/flake-parts/checks.nix-unit.nix
Normal file
17
modules/flake-parts/checks.nix-unit.nix
Normal file
@ -0,0 +1,17 @@
|
||||
# evaluate packages from `/**/modules/drvs` and export them via `flake.packages`
|
||||
{self, ...}: {
|
||||
perSystem = {
|
||||
pkgs,
|
||||
inputs',
|
||||
...
|
||||
}: {
|
||||
# map all modules in /examples to a package output in the flake.
|
||||
checks.nix-unit = pkgs.runCommand "nix-unit-tests" {} ''
|
||||
export NIX_PATH=nixpkgs=${pkgs.path}
|
||||
${inputs'.nix-unit.packages.nix-unit}/bin/nix-unit \
|
||||
${self}/tests/nix-unit/* \
|
||||
--eval-store $(realpath .)
|
||||
touch $out
|
||||
'';
|
||||
};
|
||||
}
|
75
tests/nix-unit/test_pip_pyproject/default.nix
Normal file
75
tests/nix-unit/test_pip_pyproject/default.nix
Normal file
@ -0,0 +1,75 @@
|
||||
{
|
||||
pkgs ? import <nixpkgs> {},
|
||||
lib ? import <nixpkgs/lib>,
|
||||
dream2nix ? (import (../../../modules + "/flake.nix")).outputs {},
|
||||
}: let
|
||||
eval = module:
|
||||
lib.evalModules {
|
||||
modules = [module];
|
||||
specialArgs = {
|
||||
inherit dream2nix;
|
||||
packageSets.nixpkgs = pkgs;
|
||||
};
|
||||
};
|
||||
in {
|
||||
# test if dependencies are flattened
|
||||
test_pip_flattened_dependencies = let
|
||||
evaled = eval {
|
||||
imports = [
|
||||
dream2nix.modules.drv-parts.pip
|
||||
];
|
||||
name = "test";
|
||||
lock.content = lib.mkForce {
|
||||
fetchPipMetadata.targets.default.flask = [];
|
||||
fetchPipMetadata.targets.default.requests = [];
|
||||
};
|
||||
pip.flattenDependencies = true;
|
||||
};
|
||||
config = evaled.config;
|
||||
in {
|
||||
expr = config.pip.rootDependencies;
|
||||
expected = {
|
||||
flask = true;
|
||||
requests = true;
|
||||
};
|
||||
};
|
||||
|
||||
# test if dependencies are ignored successfully in pip.rootDependencies
|
||||
test_pip_ignore_dependencies = let
|
||||
evaled = eval {
|
||||
imports = [
|
||||
dream2nix.modules.drv-parts.pip
|
||||
];
|
||||
name = "test";
|
||||
pip.ignoredDependencies = ["requests"];
|
||||
lock.content = lib.mkForce {
|
||||
fetchPipMetadata.targets.default.test = ["requests"];
|
||||
fetchPipMetadata.targets.default.requests = [];
|
||||
};
|
||||
};
|
||||
config = evaled.config;
|
||||
in {
|
||||
expr = config.pip.targets.default ? requests;
|
||||
expected = false;
|
||||
};
|
||||
|
||||
# test if root dependency is picked correctly
|
||||
test_pip_root_dependency = let
|
||||
evaled = eval {
|
||||
imports = [
|
||||
dream2nix.modules.drv-parts.pip
|
||||
];
|
||||
name = "test";
|
||||
lock.content = lib.mkForce {
|
||||
fetchPipMetadata.targets.default.test = ["requests"];
|
||||
fetchPipMetadata.targets.default.requests = [];
|
||||
};
|
||||
};
|
||||
config = evaled.config;
|
||||
in {
|
||||
expr = config.pip.rootDependencies;
|
||||
expected = {
|
||||
requests = true;
|
||||
};
|
||||
};
|
||||
}
|
Loading…
Reference in New Issue
Block a user