Debian Codegraph @

cross-project-tests/debuginfo-tests/dexter/dex/utils/UnitTests.py

raw
1 # DExTer : Debugging Experience Tester
2 # ~~~~~~ ~ ~~ ~ ~~
3 #
4 # Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5 # See https://llvm.org/LICENSE.txt for license information.
6 # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 """Unit test harness."""
8
9 from fnmatch import fnmatch
10 import os
11 import unittest
12
13 from io import StringIO
14
15 from dex.utils import is_native_windows, has_pywin32
16 from dex.utils import PreserveAutoColors, PrettyOutput
17 from dex.utils import Timer
18
19
20 class DexTestLoader(unittest.TestLoader):
21 def _match_path(self, path, full_path, pattern):
22 """Don't try to import platform-specific modules for the wrong platform
23 during test discovery.
24 """
25 d = os.path.basename(os.path.dirname(full_path))
26 if is_native_windows():
27 if d == "posix":
28 return False
29 if d == "windows":
30 return has_pywin32()
31 else:
32 if d == "windows":
33 return False
34 elif d == "dbgeng":
35 return False
36 return fnmatch(path, pattern)
37
38
39 def unit_tests_ok(context):
40 unittest.TestCase.maxDiff = None # remove size limit from diff output.
41
42 with Timer("unit tests"):
43 suite = DexTestLoader().discover(context.root_directory, pattern="*.py")
44 stream = StringIO()
45 result = unittest.TextTestRunner(verbosity=2, stream=stream).run(suite)
46
47 ok = result.wasSuccessful()
48 if not ok or context.options.unittest == "show-all":
49 with PreserveAutoColors(context.o):
50 context.o.auto_reds.extend([r"FAIL(ED|\:)", r"\.\.\.\s(FAIL|ERROR)$"])
51 context.o.auto_greens.extend([r"^OK$", r"\.\.\.\sok$"])
52 context.o.auto_blues.extend([r"^Ran \d+ test"])
53 context.o.default("\n")
54 for line in stream.getvalue().splitlines(True):
55 context.o.auto(line, stream=PrettyOutput.stderr)
56
57 return ok
58
59
60 class TestUnitTests(unittest.TestCase):
61 def test_sanity(self):
62 self.assertEqual(1, 1)