lib_sxng_test.sh 3.3 KB

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