lib_sxng_test.sh 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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 (.dev or .ci)
  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. if [ "$VERBOSE" = "1" ]; then
  18. TEST_NOSE2_VERBOSE="-vvv"
  19. fi
  20. test.yamllint() {
  21. build_msg TEST "[yamllint] \$YAMLLINT_FILES"
  22. pyenv.cmd yamllint --strict --format parsable "${YAMLLINT_FILES[@]}"
  23. dump_return $?
  24. }
  25. test.pylint() {
  26. ( set -e
  27. pyenv.activate
  28. PYLINT_OPTIONS="--rcfile .pylintrc"
  29. build_msg TEST "[pylint] ./searx/engines"
  30. # shellcheck disable=SC2086
  31. pylint ${PYLINT_OPTIONS} ${PYLINT_VERBOSE} \
  32. --additional-builtins="traits,supported_languages,language_aliases,logger,categories" \
  33. searx/engines
  34. build_msg TEST "[pylint] ./searx ./searxng_extra ./tests"
  35. # shellcheck disable=SC2086
  36. pylint ${PYLINT_OPTIONS} ${PYLINT_VERBOSE} \
  37. --ignore=searx/engines \
  38. searx searx/searxng.msg \
  39. searxng_extra searxng_extra/docs_prebuild \
  40. tests
  41. )
  42. dump_return $?
  43. }
  44. test.types.dev() {
  45. # use this pyright test for local tests in development / it suppress
  46. # warnings related to intentional monkey patching but gives good hints where
  47. # we need to work on SearXNG's typification.
  48. #
  49. # --> pyrightconfig.json
  50. build_msg TEST "[pyright/types] static type check of python sources"
  51. build_msg TEST " --> typeCheckingMode: on"
  52. node.env.dev
  53. build_msg TEST "[pyright/types] suppress warnings related to intentional monkey patching"
  54. # We run Pyright in the virtual environment because pyright executes
  55. # "python" to determine the Python version.
  56. pyenv.cmd npx --no-install pyright -p pyrightconfig.json \
  57. | grep -E '\.py:[0-9]+:[0-9]+'\
  58. | grep -v '/engines/.*.py.* - warning: "logger" is not defined'\
  59. | grep -v '/plugins/.*.py.* - error: "logger" is not defined'\
  60. | grep -v '/engines/.*.py.* - warning: "supported_languages" is not defined' \
  61. | grep -v '/engines/.*.py.* - warning: "language_aliases" is not defined' \
  62. | grep -v '/engines/.*.py.* - warning: "categories" is not defined'
  63. # ignore exit value from pyright
  64. # dump_return ${PIPESTATUS[0]}
  65. return 0
  66. }
  67. test.types.ci() {
  68. # use this pyright test for CI / disables typeCheckingMode, needed as long
  69. # we do not have fixed all typification issues.
  70. #
  71. # --> pyrightconfig-ci.json
  72. build_msg TEST "[pyright] static type check of python sources"
  73. build_msg TEST " --> typeCheckingMode: off !!!"
  74. node.env.dev
  75. build_msg TEST "[pyright] suppress warnings related to intentional monkey patching"
  76. # We run Pyright in the virtual environment because pyright executes
  77. # "python" to determine the Python version.
  78. pyenv.cmd npx --no-install pyright -p pyrightconfig-ci.json \
  79. | grep -E '\.py:[0-9]+:[0-9]+'\
  80. | grep -v '/engines/.*.py.* - warning: "logger" is not defined'\
  81. | grep -v '/plugins/.*.py.* - error: "logger" is not defined'\
  82. | grep -v '/engines/.*.py.* - warning: "supported_languages" is not defined' \
  83. | grep -v '/engines/.*.py.* - warning: "language_aliases" is not defined' \
  84. | grep -v '/engines/.*.py.* - warning: "categories" is not defined'
  85. # ignore exit value from pyright
  86. # dump_return ${PIPESTATUS[0]}
  87. return 0
  88. }
  89. test.black() {
  90. build_msg TEST "[black] \$BLACK_TARGETS"
  91. pyenv.cmd black --check --diff "${BLACK_OPTIONS[@]}" "${BLACK_TARGETS[@]}"
  92. dump_return $?
  93. }
  94. test.unit() {
  95. build_msg TEST 'tests/unit'
  96. # shellcheck disable=SC2086
  97. pyenv.cmd python -m nose2 ${TEST_NOSE2_VERBOSE} -s tests/unit
  98. dump_return $?
  99. }
  100. test.coverage() {
  101. build_msg TEST 'unit test coverage'
  102. ( set -e
  103. pyenv.activate
  104. # shellcheck disable=SC2086
  105. python -m nose2 ${TEST_NOSE2_VERBOSE} -C --log-capture --with-coverage --coverage searx -s tests/unit
  106. coverage report
  107. coverage html
  108. )
  109. dump_return $?
  110. }
  111. test.robot() {
  112. build_msg TEST 'robot'
  113. gecko.driver
  114. PYTHONPATH=. pyenv.cmd python -m tests.robot
  115. dump_return $?
  116. }
  117. test.rst() {
  118. build_msg TEST "[reST markup] ${RST_FILES[*]}"
  119. for rst in "${RST_FILES[@]}"; do
  120. pyenv.cmd rst2html --halt error "$rst" > /dev/null || die 42 "fix issue in $rst"
  121. done
  122. }
  123. test.themes() {
  124. build_msg TEST 'SearXNG themes'
  125. themes.test
  126. dump_return $?
  127. }
  128. test.pybabel() {
  129. TEST_BABEL_FOLDER="build/test/pybabel"
  130. build_msg TEST "[extract messages] pybabel"
  131. mkdir -p "${TEST_BABEL_FOLDER}"
  132. pyenv.cmd pybabel extract -F babel.cfg -o "${TEST_BABEL_FOLDER}/messages.pot" searx
  133. }
  134. test.clean() {
  135. build_msg CLEAN "test stuff"
  136. rm -rf geckodriver.log .coverage coverage/
  137. dump_return $?
  138. }