runtests.py 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. #
  4. # Copyright (c) 2016-present, Facebook, Inc.
  5. # All rights reserved.
  6. #
  7. # This source code is licensed under the BSD-style license found in the
  8. # LICENSE file in the root directory of this source tree. An additional grant
  9. # of patent rights can be found in the PATENTS file in the same directory.
  10. #
  11. # To run the integration tests you must first fetch all the required test data.
  12. # Have a look at tests/fetch_test_data.sh
  13. # You will then need to point this script to the corresponding folder
  14. from __future__ import absolute_import
  15. from __future__ import division
  16. from __future__ import print_function
  17. from __future__ import unicode_literals
  18. import unittest
  19. import argparse
  20. from fastText.tests import gen_tests
  21. from fastText.tests import gen_unit_tests
  22. def run_tests(tests):
  23. suite = unittest.TestLoader().loadTestsFromTestCase(tests)
  24. unittest.TextTestRunner(verbosity=3).run(suite)
  25. if __name__ == "__main__":
  26. parser = argparse.ArgumentParser()
  27. parser.add_argument(
  28. "-u", "--unit-tests", help="run unit tests", action="store_true"
  29. )
  30. parser.add_argument(
  31. "-i",
  32. "--integration-tests",
  33. help="run integration tests",
  34. action="store_true"
  35. )
  36. parser.add_argument(
  37. "-v",
  38. "--verbose",
  39. default=1,
  40. help="verbosity level (default 1)",
  41. type=int,
  42. )
  43. parser.add_argument("--data-dir", help="Full path to data directory")
  44. args = parser.parse_args()
  45. if args.unit_tests:
  46. run_tests(gen_unit_tests(verbose=args.verbose))
  47. if args.integration_tests:
  48. if args.data_dir is None:
  49. raise ValueError(
  50. "Need data directory! Consult tests/fetch_test_data.sh"
  51. )
  52. run_tests(gen_tests(args.data_dir, verbose=args.verbose))
  53. if not args.unit_tests and not args.integration_tests:
  54. print("Ran no tests")