~ruther/guix-local

100a25e4407212a562ad5c21d0c05db7399b8da4 — Hartmut Goebel 8 months ago 7fd0609
gnu: tryton-phases: Adjust for modern trytond and use pytest.

The former 'run-tests.py' script was removes upstream. We use pytest for
testing to allow excluding failing tests easily via arguments to
'(tryton-arguments)'.

* gnu/packages/tryton.scm[%pytest.ini): New variable.
(tryton-phases): Rename parameter extra-arguments to extra-test-arguments.
Update doc-string.  Convert to g-expression.  [prepare-check]: New phase.
[check]: Run pytest instead of 'run-tests.py'.
(tryton-arguments): Return a list (to be used in g-expressions).

Change-Id: Id7b4b480de5ba8d7a19eeff3eb2d205ba7f2e210
1 files changed, 40 insertions(+), 15 deletions(-)

M gnu/packages/tryton.scm
M gnu/packages/tryton.scm => gnu/packages/tryton.scm +40 -15
@@ 184,26 184,51 @@ and security.")
     "This package provides a library to access Tryton server as a client.")
    (license license:lgpl3+)))

(define (tryton-phases module . extra-arguments)
;; Suppress common useless warnings to avoid cluttering output
(define %pytest.ini "
[pytest]
filterwarnings =
  ignore:.*SQLite backend.*:UserWarning
  ignore:Can not create index with parameters:UserWarning
  ignore::DeprecationWarning
")

(define (tryton-phases module . extra-test-arguments)
  "Return the phases for building and testing a Tryton module named MODULE.
If present, pass EXTRA-ARGUMENTS to runtest as well."
  `(modify-phases %standard-phases
     (replace 'check
       (lambda* (#:key inputs outputs tests? #:allow-other-keys)
         (let ((runtest
                (string-append
                 (assoc-ref inputs "trytond")
                 "/lib/python"
                 ,(version-major+minor (package-version python))
                 "/site-packages/trytond/tests/run-tests.py")))
           (when tests?
             (add-installed-pythonpath inputs outputs)
             (invoke "python" runtest "-m" ,module ,@extra-arguments)))))))
If present, pass EXTRA-TEST-ARGUMENTS to pytest as well."
  #~(modify-phases %standard-phases
      (add-before 'check 'prepare-check
        (lambda* (#:key tests? #:allow-other-keys)
          (when tests?
            (setenv "DB_NAME" ":memory:")
            (setenv "DB_CACHE" "/tmp")
            (setenv "HOME" "/tmp")
            ;; Fake this directory as a tryton.module.… sub-module.
            (mkdir-p "/tmp/dummy/trytond/modules")
            (symlink (getcwd) (string-append "/tmp/dummy/trytond/modules/" #$module))
            (setenv "GUIX_TRYTOND_MODULES_PATH"
                    (string-append (getenv "GUIX_TRYTOND_MODULES_PATH")
                                   ":/tmp/dummy/trytond/modules"))
            ;; Create pytest.ini in sub-dir to make that dir pytest's
            ;; "rootdir" and avoid that the module's files get scanned (which
            ;; will fail since here they are not part of a package).
            (with-output-to-file "tests/pytest.ini"
              (lambda ()
                (format #t #$%pytest.ini))))))
      (replace 'check
        (lambda* (#:key tests? #:allow-other-keys)
          (when tests?
            ;; Use pytest to allow excluding failing tests via command line
            ;; args (resp. arguments to '(tryton-arguments)')
            (invoke "pytest" "--tb=short" "-v"
                    "--config-file=tests/pytest.ini"
                    "tests"
                    #$@extra-test-arguments))))))

(define (tryton-arguments module . extra-arguments)
  "Like ’tryton-phases’, but directly return all arguments for
the build system."
  `(#:phases ,(apply tryton-phases module extra-arguments)))
  (list #:phases (apply tryton-phases module extra-arguments)))

;;;
;;;  Tryton modules - please sort alphabetically