test.py 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #!/usr/bin/env python
  2. # Copyright (c) 2006-2011 Mitch Garnaat http://garnaat.org/
  3. #
  4. # Permission is hereby granted, free of charge, to any person obtaining a
  5. # copy of this software and associated documentation files (the
  6. # "Software"), to deal in the Software without restriction, including
  7. # without limitation the rights to use, copy, modify, merge, publish, dis-
  8. # tribute, sublicense, and/or sell copies of the Software, and to permit
  9. # persons to whom the Software is furnished to do so, subject to the fol-
  10. # lowing conditions:
  11. #
  12. # The above copyright notice and this permission notice shall be included
  13. # in all copies or substantial portions of the Software.
  14. #
  15. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  16. # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL-
  17. # ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
  18. # SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  19. # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  21. # IN THE SOFTWARE.
  22. from __future__ import print_function
  23. import argparse
  24. import os
  25. import sys
  26. from nose.core import run
  27. def main():
  28. description = ("Runs boto unit and/or integration tests. "
  29. "Arguments will be passed on to nosetests. "
  30. "See nosetests --help for more information.")
  31. parser = argparse.ArgumentParser(description=description)
  32. parser.add_argument('-t', '--service-tests', action="append", default=[],
  33. help="Run tests for a given service. This will "
  34. "run any test tagged with the specified value, "
  35. "e.g -t s3 -t ec2")
  36. known_args, remaining_args = parser.parse_known_args()
  37. attribute_args = []
  38. for service_attribute in known_args.service_tests:
  39. attribute_args.extend(['-a', '!notdefault,' + service_attribute])
  40. if not attribute_args:
  41. # If the user did not specify any filtering criteria, we at least
  42. # will filter out any test tagged 'notdefault'.
  43. attribute_args = ['-a', '!notdefault']
  44. # Set default tests used by e.g. tox. For Py2 this means all unit
  45. # tests, while for Py3 it's just whitelisted ones.
  46. if 'default' in remaining_args:
  47. # Run from the base project directory
  48. os.chdir(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
  49. for i, arg in enumerate(remaining_args):
  50. if arg == 'default':
  51. remaining_args[i] = 'tests/unit'
  52. all_args = [__file__] + attribute_args + remaining_args
  53. print("nose command:", ' '.join(all_args))
  54. if run(argv=all_args):
  55. # run will return True is all the tests pass. We want
  56. # this to equal a 0 rc
  57. return 0
  58. else:
  59. return 1
  60. if __name__ == "__main__":
  61. sys.exit(main())