runtests.py 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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 MIT license found in the
  8. # LICENSE file in the root directory of this source tree.
  9. #
  10. # To run the integration tests you must first fetch all the required test data.
  11. # Have a look at tests/fetch_test_data.sh
  12. # You will then need to point this script to the corresponding folder
  13. from __future__ import absolute_import
  14. from __future__ import division
  15. from __future__ import print_function
  16. from __future__ import unicode_literals
  17. import unittest
  18. import argparse
  19. from fasttext.tests import gen_tests
  20. from fasttext.tests import gen_unit_tests
  21. def run_tests(tests):
  22. suite = unittest.TestLoader().loadTestsFromTestCase(tests)
  23. unittest.TextTestRunner(verbosity=3).run(suite)
  24. if __name__ == "__main__":
  25. parser = argparse.ArgumentParser()
  26. parser.add_argument(
  27. "-u", "--unit-tests", help="run unit tests", action="store_true"
  28. )
  29. parser.add_argument(
  30. "-i",
  31. "--integration-tests",
  32. help="run integration tests",
  33. action="store_true"
  34. )
  35. parser.add_argument(
  36. "-v",
  37. "--verbose",
  38. default=1,
  39. help="verbosity level (default 1)",
  40. type=int,
  41. )
  42. parser.add_argument("--data-dir", help="Full path to data directory")
  43. args = parser.parse_args()
  44. if args.unit_tests:
  45. run_tests(gen_unit_tests(verbose=args.verbose))
  46. if args.integration_tests:
  47. if args.data_dir is None:
  48. raise ValueError(
  49. "Need data directory! Consult tests/fetch_test_data.sh"
  50. )
  51. run_tests(gen_tests(args.data_dir, verbose=args.verbose))
  52. if not args.unit_tests and not args.integration_tests:
  53. print("Ran no tests")