From bbfb3198b8070178994239e2ee9653fc11ad695e Mon Sep 17 00:00:00 2001 From: "Robert T. McGibbon" Date: Sun, 24 Jan 2021 18:32:43 -0500 Subject: [PATCH] Add check 'python-include-tests' --- overlays/python-include-tests.nix | 28 +++++++++++++++++++ run-tests.py | 13 +++++++++ tests/default.nix | 1 + tests/python-include-tests/default.nix | 13 +++++++++ .../explicit-check-phase.nix | 10 +++++++ .../has-imports-check.nix | 10 +++++++ .../no-tests-no-import-checks.nix | 8 ++++++ .../pytest-check-hook.nix | 11 ++++++++ .../tests-disabled-no-import-checks.nix | 12 ++++++++ 9 files changed, 106 insertions(+) create mode 100644 overlays/python-include-tests.nix create mode 100644 tests/python-include-tests/default.nix create mode 100644 tests/python-include-tests/explicit-check-phase.nix create mode 100644 tests/python-include-tests/has-imports-check.nix create mode 100644 tests/python-include-tests/no-tests-no-import-checks.nix create mode 100644 tests/python-include-tests/pytest-check-hook.nix create mode 100644 tests/python-include-tests/tests-disabled-no-import-checks.nix diff --git a/overlays/python-include-tests.nix b/overlays/python-include-tests.nix new file mode 100644 index 0000000..3f64597 --- /dev/null +++ b/overlays/python-include-tests.nix @@ -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 diff --git a/run-tests.py b/run-tests.py index e1c9939..96bdd15 100755 --- a/run-tests.py +++ b/run-tests.py @@ -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', [ diff --git a/tests/default.nix b/tests/default.nix index 7ea3174..82e6b7b 100644 --- a/tests/default.nix +++ b/tests/default.nix @@ -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 { }; } diff --git a/tests/python-include-tests/default.nix b/tests/python-include-tests/default.nix new file mode 100644 index 0000000..b79f159 --- /dev/null +++ b/tests/python-include-tests/default.nix @@ -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 { }; +} diff --git a/tests/python-include-tests/explicit-check-phase.nix b/tests/python-include-tests/explicit-check-phase.nix new file mode 100644 index 0000000..c1def6e --- /dev/null +++ b/tests/python-include-tests/explicit-check-phase.nix @@ -0,0 +1,10 @@ +{ buildPythonPackage +}: + +buildPythonPackage { + pname = "package"; + + src = ../fixtures/make; + + checkPhase = ""; +} diff --git a/tests/python-include-tests/has-imports-check.nix b/tests/python-include-tests/has-imports-check.nix new file mode 100644 index 0000000..c21c171 --- /dev/null +++ b/tests/python-include-tests/has-imports-check.nix @@ -0,0 +1,10 @@ +{ buildPythonPackage +}: + +buildPythonPackage { + pname = "package"; + + src = ../fixtures/make; + + pythonImportsCheck = []; +} diff --git a/tests/python-include-tests/no-tests-no-import-checks.nix b/tests/python-include-tests/no-tests-no-import-checks.nix new file mode 100644 index 0000000..2add48d --- /dev/null +++ b/tests/python-include-tests/no-tests-no-import-checks.nix @@ -0,0 +1,8 @@ +{ buildPythonPackage +}: + +buildPythonPackage { + pname = "package"; + + src = ../fixtures/make; +} diff --git a/tests/python-include-tests/pytest-check-hook.nix b/tests/python-include-tests/pytest-check-hook.nix new file mode 100644 index 0000000..aa6a5a0 --- /dev/null +++ b/tests/python-include-tests/pytest-check-hook.nix @@ -0,0 +1,11 @@ +{ buildPythonPackage +, pytestCheckHook +}: + +buildPythonPackage { + pname = "package"; + + src = ../fixtures/make; + + checkInputs = [ pytestCheckHook ]; +} diff --git a/tests/python-include-tests/tests-disabled-no-import-checks.nix b/tests/python-include-tests/tests-disabled-no-import-checks.nix new file mode 100644 index 0000000..894eeb9 --- /dev/null +++ b/tests/python-include-tests/tests-disabled-no-import-checks.nix @@ -0,0 +1,12 @@ +{ buildPythonPackage +, pytestCheckHook +}: + +buildPythonPackage { + pname = "package"; + + src = ../fixtures/make; + + checkInputs = [ pytestCheckHook ]; + doCheck = false; +}