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"

lldb/test/API/commands/statistics/basic/TestStats.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -600,7 +600,7 @@ def test_had_frame_variable_errors(self):
600600
# Get stats and verify we had errors.
601601
stats = self.get_stats()
602602
exe_stats = self.find_module_in_metrics(exe, stats)
603-
self.assertTrue(exe_stats is not None)
603+
self.assertIsNotNone(exe_stats)
604604

605605
# Make sure we have "debugInfoHadVariableErrors" variable that is set to
606606
# false before failing to get local variables due to missing .o file.
@@ -620,7 +620,7 @@ def test_had_frame_variable_errors(self):
620620
# Get stats and verify we had errors.
621621
stats = self.get_stats()
622622
exe_stats = self.find_module_in_metrics(exe, stats)
623-
self.assertTrue(exe_stats is not None)
623+
self.assertIsNotNone(exe_stats)
624624

625625
# Make sure we have "hadFrameVariableErrors" variable that is set to
626626
# true after failing to get local variables due to missing .o file.

lldb/test/API/commands/trace/TestTraceExport.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ def _testHtrBasicSuperBlockPassSequenceCheck(self):
229229
index_of_first_layer_1_block = None
230230
for i, event in enumerate(data):
231231
layer_id = event.get("pid")
232-
self.assertTrue(layer_id is not None)
232+
self.assertIsNotNone(layer_id)
233233
if layer_id == 1 and index_of_first_layer_1_block is None:
234234
index_of_first_layer_1_block = i
235235
num_units_by_layer[layer_id] += 1

lldb/test/API/commands/trace/TestTraceSave.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ def checkSessionBundle(session_file_path):
103103
with open(session_file_path) as session_file:
104104
session = json.load(session_file)
105105
# We expect tsc conversion info
106-
self.assertTrue("tscPerfZeroConversion" in session)
106+
self.assertIn("tscPerfZeroConversion", session)
107107
# We expect at least one cpu
108108
self.assertGreater(len(session["cpus"]), 0)
109109

@@ -152,18 +152,18 @@ def checkSessionBundle(session_file_path):
152152
copied_process = find(
153153
lambda proc: proc["pid"] == process["pid"], copy["processes"]
154154
)
155-
self.assertTrue(copied_process is not None)
155+
self.assertIsNotNone(copied_process)
156156

157157
for thread in process["threads"]:
158158
copied_thread = find(
159159
lambda thr: thr["tid"] == thread["tid"],
160160
copied_process["threads"],
161161
)
162-
self.assertTrue(copied_thread is not None)
162+
self.assertIsNotNone(copied_thread)
163163

164164
for cpu in original["cpus"]:
165165
copied_cpu = find(lambda cor: cor["id"] == cpu["id"], copy["cpus"])
166-
self.assertTrue(copied_cpu is not None)
166+
self.assertIsNotNone(copied_cpu)
167167

168168
def testSaveTrace(self):
169169
self.expect(
@@ -225,7 +225,7 @@ def testSaveKernelTrace(self):
225225
original_file = json.load(original_file)
226226
with open(copied_trace_file) as copy_file:
227227
copy_file = json.load(copy_file)
228-
self.assertTrue("kernel" in copy_file)
228+
self.assertIn("kernel", copy_file)
229229

230230
self.assertEqual(
231231
os.path.basename(original_file["kernel"]["file"]),

lldb/test/API/commands/trace/multiple-threads/TestTraceStartStopMultipleThreads.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ def testStartPerCpuSession(self):
236236
].strip()
237237
output = json.loads(response)
238238

239-
self.assertTrue(output is not None)
239+
self.assertIsNotNone(output)
240240
self.assertIn("cpus", output)
241241
self.assertIn("tscPerfZeroConversion", output)
242242
found_non_empty_context_switch = False
@@ -249,8 +249,8 @@ def testStartPerCpuSession(self):
249249
ipt_trace_size = binary_data["size"]
250250
elif binary_data["kind"] == "perfContextSwitchTrace":
251251
context_switch_size = binary_data["size"]
252-
self.assertTrue(context_switch_size is not None)
253-
self.assertTrue(ipt_trace_size is not None)
252+
self.assertIsNotNone(context_switch_size)
253+
self.assertIsNotNone(ipt_trace_size)
254254
if context_switch_size > 0:
255255
found_non_empty_context_switch = True
256256

lldb/test/API/functionalities/archives/TestBSDArchives.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,13 +85,15 @@ def check_frame_variable_errors(self, thread, error_strings):
8585
api_error = var_list.GetError().GetCString()
8686

8787
for s in error_strings:
88-
self.assertTrue(
89-
s in command_error,
88+
self.assertIn(
89+
s,
90+
command_error,
9091
'Make sure "%s" exists in the command error "%s"' % (s, command_error),
9192
)
9293
for s in error_strings:
93-
self.assertTrue(
94-
s in api_error,
94+
self.assertIn(
95+
s,
96+
api_error,
9597
'Make sure "%s" exists in the API error "%s"' % (s, api_error),
9698
)
9799

lldb/test/API/functionalities/asan/TestMemoryHistory.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ def asan_tests(self):
8787
self.assertEqual(threads.GetSize(), 2)
8888

8989
history_thread = threads.GetThreadAtIndex(0)
90-
self.assertTrue(history_thread.num_frames >= 2)
90+
self.assertGreaterEqual(history_thread.num_frames, 2)
9191
self.assertEqual(
9292
history_thread.frames[1].GetLineEntry().GetFileSpec().GetFilename(),
9393
"main.c",
@@ -97,7 +97,7 @@ def asan_tests(self):
9797
)
9898

9999
history_thread = threads.GetThreadAtIndex(1)
100-
self.assertTrue(history_thread.num_frames >= 2)
100+
self.assertGreaterEqual(history_thread.num_frames, 2)
101101
self.assertEqual(
102102
history_thread.frames[1].GetLineEntry().GetFileSpec().GetFilename(),
103103
"main.c",
@@ -109,7 +109,7 @@ def asan_tests(self):
109109
# let's free the container (SBThreadCollection) and see if the
110110
# SBThreads still live
111111
threads = None
112-
self.assertTrue(history_thread.num_frames >= 2)
112+
self.assertGreaterEqual(history_thread.num_frames, 2)
113113
self.assertEqual(
114114
history_thread.frames[1].GetLineEntry().GetFileSpec().GetFilename(),
115115
"main.c",

lldb/test/API/functionalities/breakpoint/breakpoint_command/TestBreakpointCommand.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,9 @@ def test_breakpoints_with_relative_path_line_tables(self):
8686
]
8787
for path in valid_paths:
8888
bkpt = target.BreakpointCreateByLocation(path, 2)
89-
self.assertTrue(
90-
bkpt.GetNumLocations() > 0,
89+
self.assertGreater(
90+
bkpt.GetNumLocations(),
91+
0,
9192
'Couldn\'t resolve breakpoint using full path "%s" in executate "%s" with '
9293
"debug info that has relative path with matching suffix"
9394
% (path, self.getBuildArtifact("a.out")),
@@ -142,8 +143,9 @@ def test_breakpoints_with_bad_aranges(self):
142143
target = self.dbg.CreateTarget(obj_path)
143144
src_path = "/tmp/ab/main.cpp"
144145
bkpt = target.BreakpointCreateByLocation(src_path, 2)
145-
self.assertTrue(
146-
bkpt.GetNumLocations() > 0,
146+
self.assertGreater(
147+
bkpt.GetNumLocations(),
148+
0,
147149
'Couldn\'t resolve breakpoint using "%s" in executate "%s" with '
148150
"debug info that has a bad .debug_aranges section"
149151
% (src_path, self.getBuildArtifact("a.out")),
@@ -613,8 +615,9 @@ def test_breakpoints_auto_source_map_relative(self):
613615
# is a suffix of request breakpoint file path
614616
path = "/x/y/a/b/c/main.cpp"
615617
bp = target.BreakpointCreateByLocation(path, 2)
616-
self.assertTrue(
617-
bp.GetNumLocations() > 0,
618+
self.assertGreater(
619+
bp.GetNumLocations(),
620+
0,
618621
'Couldn\'t resolve breakpoint using full path "%s" in executate "%s" with '
619622
"debug info that has relative path with matching suffix"
620623
% (path, self.getBuildArtifact("a.out")),
@@ -632,8 +635,9 @@ def test_breakpoints_auto_source_map_relative(self):
632635
# equals the file path in debug info.
633636
path = "a/b/c/main.cpp"
634637
bp = target.BreakpointCreateByLocation(path, 2)
635-
self.assertTrue(
636-
bp.GetNumLocations() > 0,
638+
self.assertGreater(
639+
bp.GetNumLocations(),
640+
0,
637641
'Couldn\'t resolve breakpoint using full path "%s" in executate "%s" with '
638642
"debug info that has relative path with matching suffix"
639643
% (path, self.getBuildArtifact("a.out")),

lldb/test/API/functionalities/breakpoint/breakpoint_command/TestBreakpointCommandsFromPython.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,9 @@ def do_set_python_command_from_python(self):
7676
)
7777
self.assertTrue(no_files_bkpt, VALID_BREAKPOINT)
7878
num_locations = no_files_bkpt.GetNumLocations()
79-
self.assertTrue(num_locations >= 2, "Got at least two breakpoint locations")
79+
self.assertGreaterEqual(
80+
num_locations, 2, "Got at least two breakpoint locations"
81+
)
8082
got_one_in_A = False
8183
got_one_in_B = False
8284
for idx in range(0, num_locations):

lldb/test/API/functionalities/breakpoint/breakpoint_conditions/TestBreakpointConditions.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,8 @@ def breakpoint_conditions_python(self):
143143
"The thread index should be invalid",
144144
)
145145
# The thread name should be invalid, too.
146-
self.assertTrue(
147-
breakpoint.GetThreadName() is None, "The thread name should be invalid"
146+
self.assertIsNone(
147+
breakpoint.GetThreadName(), "The thread name should be invalid"
148148
)
149149

150150
# Let's set the thread index for this breakpoint and verify that it is,

lldb/test/API/functionalities/breakpoint/hardware_breakpoints/require_hw_breakpoints/TestRequireHWBreakpoints.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ def test_step_range(self):
4545
error = lldb.SBError()
4646
thread.StepInto("", 4, error)
4747
self.assertTrue(error.Fail())
48-
self.assertTrue(
49-
"Could not create hardware breakpoint for thread plan" in error.GetCString()
48+
self.assertIn(
49+
"Could not create hardware breakpoint for thread plan", error.GetCString()
5050
)
5151

5252
@skipTestIfFn(HardwareBreakpointTestBase.supports_hw_breakpoints)
@@ -67,8 +67,8 @@ def test_step_out(self):
6767
error = lldb.SBError()
6868
thread.StepOut(error)
6969
self.assertTrue(error.Fail())
70-
self.assertTrue(
71-
"Could not create hardware breakpoint for thread plan" in error.GetCString()
70+
self.assertIn(
71+
"Could not create hardware breakpoint for thread plan", error.GetCString()
7272
)
7373

7474
@skipTestIfFn(HardwareBreakpointTestBase.supports_hw_breakpoints)
@@ -107,6 +107,6 @@ def test_step_until(self):
107107
# Ensure we fail when stepping through the API.
108108
error = thread.StepOverUntil(lldb.SBFrame(), lldb.SBFileSpec(), 5)
109109
self.assertTrue(error.Fail())
110-
self.assertTrue(
111-
"Could not create hardware breakpoint for thread plan" in error.GetCString()
110+
self.assertIn(
111+
"Could not create hardware breakpoint for thread plan", error.GetCString()
112112
)

lldb/test/API/functionalities/breakpoint/objc/TestObjCBreakpoints.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,9 @@ def check_category_breakpoints(self):
4242
)
4343
for bp_loc in selector_bp:
4444
function_name = bp_loc.GetAddress().GetSymbol().GetName()
45-
self.assertTrue(
46-
" myCategoryFunction]" in function_name,
45+
self.assertIn(
46+
" myCategoryFunction]",
47+
function_name,
4748
'Make sure all function names have " myCategoryFunction]" in their names',
4849
)
4950

@@ -108,8 +109,9 @@ def check_objc_breakpoints(self, have_dsym):
108109
) # There are 93 on the latest MacOSX
109110
for bp_loc in selector_bp:
110111
function_name = bp_loc.GetAddress().GetSymbol().GetName()
111-
self.assertTrue(
112-
" count]" in function_name,
112+
self.assertIn(
113+
" count]",
114+
function_name,
113115
'Make sure all function names have " count]" in their names',
114116
)
115117

@@ -132,8 +134,9 @@ def check_objc_breakpoints(self, have_dsym):
132134
)
133135
for bp_loc in selector_bp:
134136
function_name = bp_loc.GetAddress().GetSymbol().GetName()
135-
self.assertTrue(
136-
" isEqual:]" in function_name,
137+
self.assertIn(
138+
" isEqual:]",
139+
function_name,
137140
'Make sure all function names have " isEqual:]" in their names',
138141
)
139142

0 commit comments

Comments
 (0)