aboutsummaryrefslogtreecommitdiff
path: root/lldb/packages/Python/lldbsuite/test/lldbtest.py
diff options
context:
space:
mode:
authorJordan Rupprecht <rupprecht@google.com>2024-02-13 14:19:41 -0800
committerGitHub <noreply@github.com>2024-02-13 16:19:41 -0600
commit5b386158aacac4b41126983a5379d36ed413d0ea (patch)
treeb32bba399bbf4114f5618d35cb6597a9824238a7 /lldb/packages/Python/lldbsuite/test/lldbtest.py
parentc92bf6b689a1b6c662f3fb30318c67257dbca864 (diff)
downloadllvm-5b386158aacac4b41126983a5379d36ed413d0ea.zip
llvm-5b386158aacac4b41126983a5379d36ed413d0ea.tar.gz
llvm-5b386158aacac4b41126983a5379d36ed413d0ea.tar.bz2
[lldb][test] Switch LLDB API tests from vendored unittest2 to unittest (#79945)
This removes the dependency LLDB API tests have on lldb/third_party/Python/module/unittest2, and instead uses the standard one provided by Python. This does not actually remove the vendored dep yet, nor update the docs. I'll do both those once this sticks. Non-trivial changes to call out: - expected failures (i.e. "bugnumber") don't have a reason anymore, so those params were removed - `assertItemsEqual` is now called `assertCountEqual` - When a test is marked xfail, our copy of unittest2 considers failures during teardown to be OK, but modern unittest does not. See TestThreadLocal.py. (Very likely could be a real bug/leak). - Our copy of unittest2 was patched to print all test results, even ones that don't happen, e.g. `(5 passes, 0 failures, 1 errors, 0 skipped, ...)`, but standard unittest prints a terser message that omits test result types that didn't happen, e.g. `OK (skipped=1)`. Our lit integration parses this stderr and needs to be updated w/ that expectation. I tested this w/ `ninja check-lldb-api` on Linux. There's a good chance non-Linux tests have similar quirks, but I'm not able to uncover those.
Diffstat (limited to 'lldb/packages/Python/lldbsuite/test/lldbtest.py')
-rw-r--r--lldb/packages/Python/lldbsuite/test/lldbtest.py28
1 files changed, 9 insertions, 19 deletions
diff --git a/lldb/packages/Python/lldbsuite/test/lldbtest.py b/lldb/packages/Python/lldbsuite/test/lldbtest.py
index d944b09..018f2a0 100644
--- a/lldb/packages/Python/lldbsuite/test/lldbtest.py
+++ b/lldb/packages/Python/lldbsuite/test/lldbtest.py
@@ -44,7 +44,7 @@ import time
import traceback
# Third-party modules
-import unittest2
+import unittest
# LLDB modules
import lldb
@@ -517,7 +517,7 @@ def builder_module():
return lldbplatformutil.builder_module()
-class Base(unittest2.TestCase):
+class Base(unittest.TestCase):
"""
Abstract base for performing lldb (see TestBase) or other generic tests (see
BenchBase for one example). lldbtest.Base works with the test driver to
@@ -1090,17 +1090,14 @@ class Base(unittest2.TestCase):
# Once by the Python unittest framework, and a second time by us.
print("FAIL", file=sbuf)
- def markExpectedFailure(self, err, bugnumber):
+ def markExpectedFailure(self, err):
"""Callback invoked when an expected failure/error occurred."""
self.__expected__ = True
with recording(self, False) as sbuf:
# False because there's no need to write "expected failure" to the
# stderr twice.
# Once by the Python unittest framework, and a second time by us.
- if bugnumber is None:
- print("expected failure", file=sbuf)
- else:
- print("expected failure (problem id:" + str(bugnumber) + ")", file=sbuf)
+ print("expected failure", file=sbuf)
def markSkippedTest(self):
"""Callback invoked when a test is skipped."""
@@ -1111,19 +1108,14 @@ class Base(unittest2.TestCase):
# Once by the Python unittest framework, and a second time by us.
print("skipped test", file=sbuf)
- def markUnexpectedSuccess(self, bugnumber):
+ def markUnexpectedSuccess(self):
"""Callback invoked when an unexpected success occurred."""
self.__unexpected__ = True
with recording(self, False) as sbuf:
# False because there's no need to write "unexpected success" to the
# stderr twice.
# Once by the Python unittest framework, and a second time by us.
- if bugnumber is None:
- print("unexpected success", file=sbuf)
- else:
- print(
- "unexpected success (problem id:" + str(bugnumber) + ")", file=sbuf
- )
+ print("unexpected success", file=sbuf)
def getRerunArgs(self):
return " -f %s.%s" % (self.__class__.__name__, self._testMethodName)
@@ -1704,13 +1696,11 @@ class LLDBTestCaseFactory(type):
xfail_reason = xfail_for_debug_info_cat_fn(cat)
if xfail_reason:
- test_method = unittest2.expectedFailure(xfail_reason)(
- test_method
- )
+ test_method = unittest.expectedFailure(test_method)
skip_reason = skip_for_debug_info_cat_fn(cat)
if skip_reason:
- test_method = unittest2.skip(skip_reason)(test_method)
+ test_method = unittest.skip(skip_reason)(test_method)
newattrs[method_name] = test_method
@@ -2226,7 +2216,7 @@ class TestBase(Base, metaclass=LLDBTestCaseFactory):
match_strings = lldb.SBStringList()
interp.HandleCompletion(command, len(command), 0, -1, match_strings)
# match_strings is a 1-indexed list, so we have to slice...
- self.assertItemsEqual(
+ self.assertCountEqual(
completions, list(match_strings)[1:], "List of returned completion is wrong"
)