File: runtests.py

package info (click to toggle)
fasttext 0.9.2-3
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 7,800 kB
  • sloc: javascript: 10,266; cpp: 5,458; python: 2,425; sh: 616; makefile: 102; xml: 81; perl: 43
file content (60 lines) | stat: -rw-r--r-- 1,820 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Copyright (c) 2016-present, Facebook, Inc.
# All rights reserved.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
#

# To run the integration tests you must first fetch all the required test data.
# Have a look at tests/fetch_test_data.sh
# You will then need to point this script to the corresponding folder

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals

import unittest
import argparse
from fasttext.tests import gen_tests
from fasttext.tests import gen_unit_tests


def run_tests(tests):
    suite = unittest.TestLoader().loadTestsFromTestCase(tests)
    unittest.TextTestRunner(verbosity=3).run(suite)


if __name__ == "__main__":
    parser = argparse.ArgumentParser()
    parser.add_argument(
        "-u", "--unit-tests", help="run unit tests", action="store_true"
    )
    parser.add_argument(
        "-i",
        "--integration-tests",
        help="run integration tests",
        action="store_true"
    )
    parser.add_argument(
        "-v",
        "--verbose",
        default=1,
        help="verbosity level (default 1)",
        type=int,
    )
    parser.add_argument("--data-dir", help="Full path to data directory")
    args = parser.parse_args()
    if args.unit_tests:
        run_tests(gen_unit_tests(verbose=args.verbose))
    if args.integration_tests:
        if args.data_dir is None:
            raise ValueError(
                "Need data directory! Consult tests/fetch_test_data.sh"
            )
        run_tests(gen_tests(args.data_dir, verbose=args.verbose))
    if not args.unit_tests and not args.integration_tests:
        print("Ran no tests")