lib_sxng_test.sh 5.2 KB

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