1from __future__ import print_function
2import sys
3import unittest
4from fontParts.test import test_normalizers
5from fontParts.test import test_font
6from fontParts.test import test_info
7from fontParts.test import test_groups
8from fontParts.test import test_kerning
9from fontParts.test import test_features
10from fontParts.test import test_layer
11from fontParts.test import test_glyph
12from fontParts.test import test_contour
13from fontParts.test import test_segment
14from fontParts.test import test_bPoint
15from fontParts.test import test_point
16from fontParts.test import test_component
17from fontParts.test import test_anchor
18from fontParts.test import test_image
19from fontParts.test import test_lib
20from fontParts.test import test_guideline
21from fontParts.test import test_deprecated
22from fontParts.test import test_color
23from fontParts.test import test_world
24
25
26def testEnvironment(objectGenerator, inApp=False, verbosity=1, testNormalizers=True):
27    modules = [
28        test_font,
29        test_info,
30        test_groups,
31        test_kerning,
32        test_features,
33        test_layer,
34        test_glyph,
35        test_contour,
36        test_segment,
37        test_bPoint,
38        test_point,
39        test_component,
40        test_anchor,
41        test_image,
42        test_lib,
43        test_guideline,
44        test_deprecated,
45        test_color,
46        test_world
47    ]
48    if testNormalizers:
49        modules.append(test_normalizers)
50
51    globalSuite = unittest.TestSuite()
52    loader = unittest.TestLoader()
53    for module in modules:
54        suite = loader.loadTestsFromModule(module)
55        _setObjectGenerator(suite, objectGenerator)
56        globalSuite.addTest(suite)
57    runner = unittest.TextTestRunner(verbosity=verbosity)
58    succes = runner.run(globalSuite).wasSuccessful()
59    if not inApp:
60        sys.exit(not succes)
61    else:
62        return succes  # pragma: no cover
63
64
65def _setObjectGenerator(suite, objectGenerator):
66    for i in suite:
67        if isinstance(i, unittest.TestSuite):
68            _setObjectGenerator(i, objectGenerator)
69        else:
70            i.objectGenerator = objectGenerator
71