Skip to content

Commit

Permalink
Add check 'python-include-tests'
Browse files Browse the repository at this point in the history
  • Loading branch information
rmcgibbo committed Jan 26, 2021
1 parent c7b9316 commit bbfb319
Show file tree
Hide file tree
Showing 9 changed files with 106 additions and 0 deletions.
28 changes: 28 additions & 0 deletions overlays/python-include-tests.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{ builtAttrs
, packageSet
, namePositions
}@attrs:

final: prev:
let
inherit (prev) lib;
inherit (import ../lib { inherit lib; }) checkBuildPythonPackageFor;

checkDerivation = drvArgs: drv:
lib.singleton {
name = "python-include-tests";
cond = let
hasCheckPhase = drvArgs ? checkPhase;
hasDoCheckFalse = (drvArgs ? doCheck) && (drvArgs.doCheck == false);
hasPytestCheckHook = drvArgs ? checkInputs && lib.any (n: n.name == "pytest-check-hook") drvArgs.checkInputs;
hasPythonImportsCheck = drvArgs ? pythonImportsCheck;

hasActiveCheckPhase = (hasCheckPhase || hasPytestCheckHook) && (! hasDoCheckFalse);
in
! (hasActiveCheckPhase || hasPythonImportsCheck);
msg = ''
Add a checkPhase for tests, or at least pythonImportsCheck.
'';
};
in
checkBuildPythonPackageFor checkDerivation attrs final prev
13 changes: 13 additions & 0 deletions run-tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,19 @@ def __iter__(self):
]
)

yield make_test_rule(
'python-include-tests',
[
'no-tests-no-import-checks',
'tests-disabled-no-import-checks',
],
[
'pytest-check-hook',
'explicit-check-phase',
'has-imports-check'
]
)

yield make_test_rule(
'unnecessary-parallel-building',
[
Expand Down
1 change: 1 addition & 0 deletions tests/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
patch-phase = pkgs.callPackage ./patch-phase { };
python-explicit-check-phase = pkgs.python3.pkgs.callPackage ./python-explicit-check-phase { };
python-imports-check-typo = pkgs.python3.pkgs.callPackage ./python-imports-check-typo { };
python-include-tests = pkgs.python3.pkgs.callPackage ./python-include-tests { };
unclear-gpl = pkgs.callPackage ./unclear-gpl { };
unnecessary-parallel-building = pkgs.callPackage ./unnecessary-parallel-building { };
}
13 changes: 13 additions & 0 deletions tests/python-include-tests/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{ callPackage
}:

{
# positive cases
no-tests-no-import-checks = callPackage ./no-tests-no-import-checks.nix { };
tests-disabled-no-import-checks = callPackage ./tests-disabled-no-import-checks.nix { };

# negative cases
pytest-check-hook = callPackage ./pytest-check-hook.nix { };
explicit-check-phase = callPackage ./explicit-check-phase.nix { };
has-imports-check = callPackage ./has-imports-check.nix { };
}
10 changes: 10 additions & 0 deletions tests/python-include-tests/explicit-check-phase.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{ buildPythonPackage
}:

buildPythonPackage {
pname = "package";

src = ../fixtures/make;

checkPhase = "";
}
10 changes: 10 additions & 0 deletions tests/python-include-tests/has-imports-check.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{ buildPythonPackage
}:

buildPythonPackage {
pname = "package";

src = ../fixtures/make;

pythonImportsCheck = [];
}
8 changes: 8 additions & 0 deletions tests/python-include-tests/no-tests-no-import-checks.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{ buildPythonPackage
}:

buildPythonPackage {
pname = "package";

src = ../fixtures/make;
}
11 changes: 11 additions & 0 deletions tests/python-include-tests/pytest-check-hook.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{ buildPythonPackage
, pytestCheckHook
}:

buildPythonPackage {
pname = "package";

src = ../fixtures/make;

checkInputs = [ pytestCheckHook ];
}
12 changes: 12 additions & 0 deletions tests/python-include-tests/tests-disabled-no-import-checks.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{ buildPythonPackage
, pytestCheckHook
}:

buildPythonPackage {
pname = "package";

src = ../fixtures/make;

checkInputs = [ pytestCheckHook ];
doCheck = false;
}

0 comments on commit bbfb319

Please sign in to comment.