From 761d42472be0229efe77f09eae101c147f72d2a1 Mon Sep 17 00:00:00 2001 From: Lars-Dominik Braun Date: Tue, 20 Apr 2021 11:03:55 +0200 Subject: [PATCH 11/12] gnu: python-nbconvert: Enable more tests. Enables more tests and fixes a few paths. * gnu/packages/python-xyz.scm (python-nbconvert) [arguments]: Add new phase, fixing pandoc/LaTeX paths. Set required environment variables in 'check phase. [inputs]: Add pandoc and texlive. [native-inputs]: Add missing inputs for tests. [propagated-inputs]: Add tornado, which is always required. --- gnu/packages/python-xyz.scm | 76 +++++++++++++++++++++++++++---------- 1 file changed, 55 insertions(+), 21 deletions(-) diff --git a/gnu/packages/python-xyz.scm b/gnu/packages/python-xyz.scm index a49a395900..4202e2de17 100644 --- a/gnu/packages/python-xyz.scm +++ b/gnu/packages/python-xyz.scm @@ -10668,32 +10668,64 @@ time.") (arguments `(#:phases (modify-phases %standard-phases + (add-after 'unpack 'fix-paths-and-tests + (lambda* (#:key inputs outputs #:allow-other-keys) + (let* ((pandoc (string-append (assoc-ref inputs "pandoc") "/bin/pandoc")) + (texlive-root (string-append (assoc-ref inputs "texlive"))) + (xelatex (string-append texlive-root "/bin/xelatex")) + (bibtex (string-append texlive-root "/bin/bibtex"))) + ;; Use pandoc binary from input. + (substitute* "nbconvert/utils/pandoc.py" + (("'pandoc'") (string-append "'" pandoc "'"))) + ;; Same for LaTeX. + (substitute* "nbconvert/exporters/pdf.py" + (("\"xelatex\"") (string-append "\"" xelatex "\"")) + (("\"bibtex\"") (string-append "\"" bibtex "\""))) + ;; Make sure tests are not skipped. + (substitute* (find-files "." "test_.+\\.py$") + (("@onlyif_cmds_exist\\(('(pandoc|xelatex)'(, )?)+\\)") "")) + ;; Pandoc is never missing, disable test. + (substitute* "nbconvert/utils/tests/test_pandoc.py" + (("import os" all) (string-append all "\nimport pytest")) + (("(.+)(def test_pandoc_available)" all indent def) + (string-append indent "@pytest.mark.skip('disabled by guix')\n" + indent def))) + ; Not installing pyppeteer, delete test. + (delete-file "nbconvert/exporters/tests/test_webpdf.py") + (substitute* "nbconvert/tests/test_nbconvertapp.py" + (("(.+)(def test_webpdf_with_chromium)" all indent def) + (string-append indent "@pytest.mark.skip('disabled by guix')\n" + indent def))) + #t))) (replace 'check (lambda* (#:key tests? inputs outputs #:allow-other-keys) (when tests? + ;; Some tests invoke the installed nbconvert binary. (add-installed-pythonpath inputs outputs) - - ;; This seems to require Chromium. - (delete-file "nbconvert/exporters/tests/test_webpdf.py") - - ;; This depends on the python3 kernel, which is provided by a - ;; package that depends on nbconvert. - (delete-file "nbconvert/preprocessors/tests/test_execute.py") - - ;; Most of these tests fail because nbconvert fails to execute - ;; itself. - (delete-file "nbconvert/tests/test_nbconvertapp.py") - - ;; One test here fails with an unclear error. It looks like - ;; "%%pylabprint" is supposed to be expanded to some other - ;; code, but isn't. - (delete-file "nbconvert/filters/tests/test_strings.py") - + ;; Tries to write to this path. + (unsetenv "JUPYTER_CONFIG_DIR") + ;; Tests depend on templates installed to output. + (setenv "JUPYTER_PATH" + (string-append + (assoc-ref outputs "out") + "/share/jupyter:" + (getenv "JUPYTER_PATH"))) ;; Some tests need HOME (setenv "HOME" "/tmp") - (invoke "pytest"))))))) - (native-inputs - `(("python-pytest" ,python-pytest))) + (invoke "pytest" "-vv"))))))) + (inputs + `(("pandoc" ,pandoc) + ; XXX: Disabled, needs substitute*. + ;("inkscape" ,inkscape) + ("texlive" ,texlive))) + (native-inputs + `(("python-ipykernel" ,python-ipykernel) + ; XXX: Disabled, not in guix. + ;("python-pyppeteer" ,python-pyppeteer) + ("python-pytest" ,python-pytest) + ("python-pytest-cov" ,python-pytest-cov) + ("python-pytest-dependency" + ,python-pytest-dependency))) (propagated-inputs `(("python-bleach" ,python-bleach) ("python-defusedxml" ,python-defusedxml) @@ -10707,7 +10739,9 @@ time.") ("python-pygments" ,python-pygments) ("python-jupyterlab-pygments" ,python-jupyterlab-pygments) ("python-testpath" ,python-testpath) - ("python-traitlets" ,python-traitlets))) + ("python-traitlets" ,python-traitlets) + ;; Required, even if [serve] is not used. + ("python-tornado" ,python-tornado-6))) (home-page "https://jupyter.org") (synopsis "Converting Jupyter Notebooks") (description "The @code{nbconvert} tool, @{jupyter nbconvert}, converts -- 2.26.3