tox_support.py 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. """passlib.tests.tox_support - helper script for tox tests"""
  2. #=============================================================================
  3. # init script env
  4. #=============================================================================
  5. import os, sys
  6. root_dir = os.path.join(os.path.dirname(__file__), os.pardir, os.pardir)
  7. sys.path.insert(0, root_dir)
  8. #=============================================================================
  9. # imports
  10. #=============================================================================
  11. # core
  12. import re
  13. import logging; log = logging.getLogger(__name__)
  14. # site
  15. # pkg
  16. from passlib.utils.compat import print_
  17. # local
  18. __all__ = [
  19. ]
  20. #=============================================================================
  21. # main
  22. #=============================================================================
  23. TH_PATH = "passlib.tests.test_handlers"
  24. def do_hash_tests(*args):
  25. """return list of hash algorithm tests that match regexes"""
  26. if not args:
  27. print(TH_PATH)
  28. return
  29. suffix = ''
  30. args = list(args)
  31. while True:
  32. if args[0] == "--method":
  33. suffix = '.' + args[1]
  34. del args[:2]
  35. else:
  36. break
  37. from passlib.tests import test_handlers
  38. names = [TH_PATH + ":" + name + suffix for name in dir(test_handlers)
  39. if not name.startswith("_") and any(re.match(arg,name) for arg in args)]
  40. print_("\n".join(names))
  41. return not names
  42. def do_preset_tests(name):
  43. """return list of preset test names"""
  44. if name == "django" or name == "django-hashes":
  45. do_hash_tests("django_.*_test", "hex_md5_test")
  46. if name == "django":
  47. print_("passlib.tests.test_ext_django")
  48. else:
  49. raise ValueError("unknown name: %r" % name)
  50. def do_setup_gae(path, runtime):
  51. """write fake GAE ``app.yaml`` to current directory so nosegae will work"""
  52. from passlib.tests.utils import set_file
  53. set_file(os.path.join(path, "app.yaml"), """\
  54. application: fake-app
  55. version: 2
  56. runtime: %s
  57. api_version: 1
  58. threadsafe: no
  59. handlers:
  60. - url: /.*
  61. script: dummy.py
  62. libraries:
  63. - name: django
  64. version: "latest"
  65. """ % runtime)
  66. def main(cmd, *args):
  67. return globals()["do_" + cmd](*args)
  68. if __name__ == "__main__":
  69. import sys
  70. sys.exit(main(*sys.argv[1:]) or 0)
  71. #=============================================================================
  72. # eof
  73. #=============================================================================