lib_sxng_test.sh 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. #!/usr/bin/env bash
  2. # SPDX-License-Identifier: AGPL-3.0-or-later
  3. test.help(){
  4. cat <<EOF
  5. test.:
  6. yamllint : lint YAML files (YAMLLINT_FILES)
  7. pylint : lint ./searx, ./searxng_extra and ./tests
  8. pyright : static type check of python sources
  9. black : check black code format
  10. unit : run unit tests
  11. coverage : run unit tests with coverage
  12. robot : run robot test
  13. rst : test .rst files incl. README.rst
  14. clean : clean intermediate test stuff
  15. EOF
  16. }
  17. test.yamllint() {
  18. build_msg TEST "[yamllint] \$YAMLLINT_FILES"
  19. pyenv.cmd yamllint --strict --format parsable "${YAMLLINT_FILES[@]}"
  20. dump_return $?
  21. }
  22. test.pylint() {
  23. # shellcheck disable=SC2086
  24. ( set -e
  25. pyenv.activate
  26. PYLINT_OPTIONS="--rcfile .pylintrc"
  27. build_msg TEST "[pylint] ./searx/engines"
  28. pylint ${PYLINT_OPTIONS} ${PYLINT_VERBOSE} \
  29. --additional-builtins="traits,supported_languages,language_aliases,logger,categories" \
  30. searx/engines
  31. build_msg TEST "[pylint] ./searx ./searxng_extra ./tests"
  32. pylint ${PYLINT_OPTIONS} ${PYLINT_VERBOSE} \
  33. --ignore=searx/engines \
  34. searx searx/searxng.msg \
  35. searxng_extra searxng_extra/docs_prebuild \
  36. tests
  37. )
  38. dump_return $?
  39. }
  40. test.pyright() {
  41. build_msg TEST "[pyright] static type check of python sources"
  42. node.env.dev
  43. # We run Pyright in the virtual environment because Pyright
  44. # executes "python" to determine the Python version.
  45. build_msg TEST "[pyright] suppress warnings related to intentional monkey patching"
  46. pyenv.cmd npx --no-install pyright -p pyrightconfig-ci.json \
  47. | grep -v ".py$" \
  48. | grep -v '/engines/.*.py.* - warning: "logger" is not defined'\
  49. | grep -v '/plugins/.*.py.* - error: "logger" is not defined'\
  50. | grep -v '/engines/.*.py.* - warning: "supported_languages" is not defined' \
  51. | grep -v '/engines/.*.py.* - warning: "language_aliases" is not defined' \
  52. | grep -v '/engines/.*.py.* - warning: "categories" is not defined'
  53. dump_return $?
  54. }
  55. test.black() {
  56. build_msg TEST "[black] \$BLACK_TARGETS"
  57. pyenv.cmd black --check --diff "${BLACK_OPTIONS[@]}" "${BLACK_TARGETS[@]}"
  58. dump_return $?
  59. }
  60. test.unit() {
  61. build_msg TEST 'tests/unit'
  62. pyenv.cmd python -m nose2 -s tests/unit
  63. dump_return $?
  64. }
  65. test.coverage() {
  66. build_msg TEST 'unit test coverage'
  67. ( set -e
  68. pyenv.activate
  69. python -m nose2 -C --log-capture --with-coverage --coverage searx -s tests/unit
  70. coverage report
  71. coverage html
  72. )
  73. dump_return $?
  74. }
  75. test.robot() {
  76. build_msg TEST 'robot'
  77. gecko.driver
  78. PYTHONPATH=. pyenv.cmd python -m tests.robot
  79. dump_return $?
  80. }
  81. test.rst() {
  82. build_msg TEST "[reST markup] ${RST_FILES[*]}"
  83. for rst in "${RST_FILES[@]}"; do
  84. pyenv.cmd rst2html.py --halt error "$rst" > /dev/null || die 42 "fix issue in $rst"
  85. done
  86. }
  87. test.pybabel() {
  88. TEST_BABEL_FOLDER="build/test/pybabel"
  89. build_msg TEST "[extract messages] pybabel"
  90. mkdir -p "${TEST_BABEL_FOLDER}"
  91. pyenv.cmd pybabel extract -F babel.cfg -o "${TEST_BABEL_FOLDER}/messages.pot" searx
  92. }
  93. test.clean() {
  94. build_msg CLEAN "test stuff"
  95. rm -rf geckodriver.log .coverage coverage/
  96. dump_return $?
  97. }