Skip to content

Commit 9c24688

Browse files
authored
[lldb][test] Modernize asserts (llvm#82503)
This uses [teyit](https://pypi.org/project/teyit/) to modernize asserts, as recommended by the [unittest release notes](https://docs.python.org/3.12/whatsnew/3.12.html#id3). For example, `assertTrue(a == b)` is replaced with `assertEqual(a, b)`. This produces better error messages, e.g. `error: unexpectedly found 1 and 2 to be different` instead of `error: False`.
1 parent 4247175 commit 9c24688

File tree

99 files changed

+335
-299
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

99 files changed

+335
-299
lines changed

lldb/test/API/commands/expression/call-restarts/TestCallThatRestarts.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ def call_function(self):
8484
handler_bkpt = target.BreakpointCreateBySourceRegex(
8585
"Got sigchld %d.", self.main_source_spec
8686
)
87-
self.assertTrue(handler_bkpt.GetNumLocations() > 0)
87+
self.assertGreater(handler_bkpt.GetNumLocations(), 0)
8888
options.SetIgnoreBreakpoints(True)
8989
options.SetUnwindOnError(True)
9090

lldb/test/API/commands/expression/call-throws/TestCallThatThrows.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def call_function(self):
5555
handler_bkpt = target.BreakpointCreateBySourceRegex(
5656
"I felt like it", self.main_source_spec
5757
)
58-
self.assertTrue(handler_bkpt.GetNumLocations() > 0)
58+
self.assertGreater(handler_bkpt.GetNumLocations(), 0)
5959
options.SetIgnoreBreakpoints(True)
6060
options.SetUnwindOnError(True)
6161

@@ -69,7 +69,7 @@ def call_function(self):
6969
exception_bkpt = target.BreakpointCreateForException(
7070
lldb.eLanguageTypeObjC, False, True
7171
)
72-
self.assertTrue(exception_bkpt.GetNumLocations() > 0)
72+
self.assertGreater(exception_bkpt.GetNumLocations(), 0)
7373

7474
options.SetIgnoreBreakpoints(True)
7575
options.SetUnwindOnError(True)

lldb/test/API/commands/expression/completion-crash-invalid-iterator/TestInvalidIteratorCompletionCrash.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ def test(self):
1111
callee_break = target.BreakpointCreateByName(
1212
"SomeClass::SomeClass(ParamClass)", None
1313
)
14-
self.assertTrue(callee_break.GetNumLocations() > 0)
14+
self.assertGreater(callee_break.GetNumLocations(), 0)
1515
self.runCmd("run", RUN_SUCCEEDED)
1616

1717
to_complete = "e ParamClass"

lldb/test/API/commands/expression/fixits/TestFixIts.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,11 @@ def test_with_target(self):
7979
self.assertTrue(value.IsValid())
8080
self.assertTrue(value.GetError().Fail())
8181
error_string = value.GetError().GetCString()
82-
self.assertTrue(
83-
error_string.find("fixed expression suggested:") != -1, "Fix was suggested"
82+
self.assertNotEqual(
83+
error_string.find("fixed expression suggested:"), -1, "Fix was suggested"
8484
)
85-
self.assertTrue(
86-
error_string.find("my_pointer->second.a") != -1, "Fix was right"
85+
self.assertNotEqual(
86+
error_string.find("my_pointer->second.a"), -1, "Fix was right"
8787
)
8888

8989
def test_with_target_error_applies_fixit(self):

lldb/test/API/commands/expression/test/TestExprs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ def test_evaluate_expression_python(self):
163163
self.DebugSBValue(val)
164164

165165
callee_break = target.BreakpointCreateByName("a_function_to_call", None)
166-
self.assertTrue(callee_break.GetNumLocations() > 0)
166+
self.assertGreater(callee_break.GetNumLocations(), 0)
167167

168168
# Make sure ignoring breakpoints works from the command line:
169169
self.expect(

lldb/test/API/commands/expression/unwind_expression/TestUnwindExpression.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,9 @@ def do_unwind_test(self, thread, bkpt, timeout):
7070

7171
self.assertTrue(val.GetError().Fail(), "We did not complete the execution.")
7272
error_str = val.GetError().GetCString()
73-
self.assertTrue(
74-
"Execution was interrupted, reason: breakpoint" in error_str,
73+
self.assertIn(
74+
"Execution was interrupted, reason: breakpoint",
75+
error_str,
7576
"And the reason was right.",
7677
)
7778

lldb/test/API/commands/register/register/aarch64_sme_z_registers/save_restore/TestSMEZRegistersSaveRestore.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def get_supported_svg(self):
5555

5656
# Write back the current vg to confirm read/write works at all.
5757
current_svg = self.match("register read vg", ["(0x[0-9]+)"])
58-
self.assertTrue(current_svg is not None)
58+
self.assertIsNotNone(current_svg)
5959
self.expect("register write vg {}".format(current_svg.group()))
6060

6161
# Aka 128, 256 and 512 bit.

lldb/test/API/commands/register/register/aarch64_sme_z_registers/za_dynamic_resize/TestZAThreadedDynamic.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def get_supported_vg(self):
2828
)
2929

3030
current_vg = self.match("register read vg", ["(0x[0-9]+)"])
31-
self.assertTrue(current_vg is not None)
31+
self.assertIsNotNone(current_vg)
3232
self.expect("register write vg {}".format(current_vg.group()))
3333

3434
# Aka 128, 256 and 512 bit.

lldb/test/API/commands/register/register/aarch64_sve_registers/rw_access_dynamic_resize/TestSVEThreadedDynamic.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def get_supported_vg(self):
4040

4141
# Write back the current vg to confirm read/write works at all.
4242
current_vg = self.match("register read vg", ["(0x[0-9]+)"])
43-
self.assertTrue(current_vg is not None)
43+
self.assertIsNotNone(current_vg)
4444
self.expect("register write vg {}".format(current_vg.group()))
4545

4646
# Aka 128, 256 and 512 bit.

lldb/test/API/commands/session/save/TestSessionSave.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def test_session_save(self):
4747
raw += self.raw_transcript_builder(cmd, res)
4848

4949
self.assertTrue(interpreter.HasCommands())
50-
self.assertTrue(len(raw) != 0)
50+
self.assertNotEqual(len(raw), 0)
5151

5252
# Check for error
5353
cmd = "session save /root/file"

0 commit comments

Comments
 (0)