Skip to content

Commit 096c530

Browse files
committed
[lldb] Fix Python test formatting (NFC)
1 parent 118a2a5 commit 096c530

File tree

17 files changed

+329
-219
lines changed

17 files changed

+329
-219
lines changed

lldb/test/API/commands/command/script/add/TestAddParsedCommand.py

Lines changed: 116 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class ParsedCommandTestCase(TestBase):
1616
def test(self):
1717
self.pycmd_tests()
1818

19-
def check_help_options(self, cmd_name, opt_list, substrs = []):
19+
def check_help_options(self, cmd_name, opt_list, substrs=[]):
2020
"""
2121
Pass the command name in cmd_name and a vector of the short option, type & long option.
2222
This will append the checks for all the options and test "help command".
@@ -30,117 +30,170 @@ def check_help_options(self, cmd_name, opt_list, substrs = []):
3030
(short_opt, type, long_opt) = elem
3131
substrs.append(f"-{short_opt} <{type}> ( --{long_opt} <{type}> )")
3232
print(f"Opt Vec\n{substrs}")
33-
self.expect("help " + cmd_name, substrs = substrs)
33+
self.expect("help " + cmd_name, substrs=substrs)
3434

3535
def pycmd_tests(self):
3636
source_dir = self.getSourceDir()
3737
test_file_path = os.path.join(source_dir, "test_commands.py")
3838
self.runCmd("command script import " + test_file_path)
39-
self.expect("help", substrs = ["no-args", "one-arg-no-opt", "two-args"])
39+
self.expect("help", substrs=["no-args", "one-arg-no-opt", "two-args"])
4040

4141
# Test that we did indeed add these commands as user commands:
4242

4343
# This is the function to remove the custom commands in order to have a
4444
# clean slate for the next test case.
4545
def cleanup():
46-
self.runCmd("command script delete no-args one-arg-no-opt two-args", check=False)
46+
self.runCmd(
47+
"command script delete no-args one-arg-no-opt two-args", check=False
48+
)
4749

4850
# Execute the cleanup function during test case tear down.
4951
self.addTearDownHook(cleanup)
5052

5153
# First test the no arguments command. Make sure the help is right:
52-
no_arg_opts = [["b", "boolean", "bool-arg"],
53-
"+a boolean arg, defaults to True",
54-
["d", "filename", "disk-file-name"],
55-
"+An on disk filename",
56-
["e", "none", "enum-option"],
57-
"+An enum, doesn't actually do anything",
58-
"+Values: foo | bar | baz",
59-
["l", "linenum", "line-num"],
60-
"+A line number",
61-
["s", "shlib-name", "shlib-name"],
62-
"+A shared library name"]
63-
substrs = ["Example command for use in debugging",
64-
"Syntax: no-args <cmd-options>"]
65-
54+
no_arg_opts = [
55+
["b", "boolean", "bool-arg"],
56+
"+a boolean arg, defaults to True",
57+
["d", "filename", "disk-file-name"],
58+
"+An on disk filename",
59+
["e", "none", "enum-option"],
60+
"+An enum, doesn't actually do anything",
61+
"+Values: foo | bar | baz",
62+
["l", "linenum", "line-num"],
63+
"+A line number",
64+
["s", "shlib-name", "shlib-name"],
65+
"+A shared library name",
66+
]
67+
substrs = [
68+
"Example command for use in debugging",
69+
"Syntax: no-args <cmd-options>",
70+
]
71+
6672
self.check_help_options("no-args", no_arg_opts, substrs)
6773

6874
# Make sure the command doesn't accept arguments:
69-
self.expect("no-args an-arg", substrs=["'no-args' doesn't take any arguments."],
70-
error=True)
75+
self.expect(
76+
"no-args an-arg",
77+
substrs=["'no-args' doesn't take any arguments."],
78+
error=True,
79+
)
7180

7281
# Try setting the bool with the wrong value:
73-
self.expect("no-args -b Something",
74-
substrs=["Error setting option: bool-arg to Something"],
75-
error=True)
82+
self.expect(
83+
"no-args -b Something",
84+
substrs=["Error setting option: bool-arg to Something"],
85+
error=True,
86+
)
7687
# Try setting the enum to an illegal value as well:
77-
self.expect("no-args --enum-option Something",
78-
substrs=["error: Error setting option: enum-option to Something"],
79-
error=True)
80-
88+
self.expect(
89+
"no-args --enum-option Something",
90+
substrs=["error: Error setting option: enum-option to Something"],
91+
error=True,
92+
)
93+
8194
# Check some of the command groups:
82-
self.expect("no-args -b true -s Something -l 10",
83-
substrs=["error: invalid combination of options for the given command"],
84-
error=True)
85-
95+
self.expect(
96+
"no-args -b true -s Something -l 10",
97+
substrs=["error: invalid combination of options for the given command"],
98+
error=True,
99+
)
100+
86101
# Now set the bool arg correctly, note only the first option was set:
87-
self.expect("no-args -b true", substrs=["bool-arg (set: True): True",
88-
"shlib-name (set: False):",
89-
"disk-file-name (set: False):",
90-
"line-num (set: False):",
91-
"enum-option (set: False):"])
102+
self.expect(
103+
"no-args -b true",
104+
substrs=[
105+
"bool-arg (set: True): True",
106+
"shlib-name (set: False):",
107+
"disk-file-name (set: False):",
108+
"line-num (set: False):",
109+
"enum-option (set: False):",
110+
],
111+
)
92112

93113
# Now set the enum arg correctly, note only the first option was set:
94-
self.expect("no-args -e foo", substrs=["bool-arg (set: False):",
95-
"shlib-name (set: False):",
96-
"disk-file-name (set: False):",
97-
"line-num (set: False):",
98-
"enum-option (set: True): foo"])
114+
self.expect(
115+
"no-args -e foo",
116+
substrs=[
117+
"bool-arg (set: False):",
118+
"shlib-name (set: False):",
119+
"disk-file-name (set: False):",
120+
"line-num (set: False):",
121+
"enum-option (set: True): foo",
122+
],
123+
)
99124
# Try a pair together:
100-
self.expect("no-args -b false -s Something", substrs=["bool-arg (set: True): False",
101-
"shlib-name (set: True): Something",
102-
"disk-file-name (set: False):",
103-
"line-num (set: False):",
104-
"enum-option (set: False):"])
125+
self.expect(
126+
"no-args -b false -s Something",
127+
substrs=[
128+
"bool-arg (set: True): False",
129+
"shlib-name (set: True): Something",
130+
"disk-file-name (set: False):",
131+
"line-num (set: False):",
132+
"enum-option (set: False):",
133+
],
134+
)
105135

106136
# Next try some completion tests:
107137

108138
interp = self.dbg.GetCommandInterpreter()
109139
matches = lldb.SBStringList()
110140
descriptions = lldb.SBStringList()
111141

112-
# First try an enum completion:
113-
num_completions = interp.HandleCompletionWithDescriptions("no-args -e f", 12, 0,
114-
1000, matches, descriptions)
142+
# First try an enum completion:
143+
num_completions = interp.HandleCompletionWithDescriptions(
144+
"no-args -e f", 12, 0, 1000, matches, descriptions
145+
)
115146
self.assertEqual(num_completions, 1, "Only one completion for foo")
116-
self.assertEqual(matches.GetSize(), 2, "The first element is the complete additional text")
117-
self.assertEqual(matches.GetStringAtIndex(0), "oo ", "And we got the right extra characters")
118-
self.assertEqual(matches.GetStringAtIndex(1), "foo", "And we got the right match")
119-
self.assertEqual(descriptions.GetSize(), 2, "descriptions matche the return length")
147+
self.assertEqual(
148+
matches.GetSize(), 2, "The first element is the complete additional text"
149+
)
150+
self.assertEqual(
151+
matches.GetStringAtIndex(0), "oo ", "And we got the right extra characters"
152+
)
153+
self.assertEqual(
154+
matches.GetStringAtIndex(1), "foo", "And we got the right match"
155+
)
156+
self.assertEqual(
157+
descriptions.GetSize(), 2, "descriptions matche the return length"
158+
)
120159
# FIXME: we don't return descriptions for enum elements
121-
#self.assertEqual(descriptions.GetStringAtIndex(1), "does foo things", "And we got the right description")
160+
# self.assertEqual(descriptions.GetStringAtIndex(1), "does foo things", "And we got the right description")
122161

123162
# Now try an internal completer, the on disk file one is handy:
124163
partial_name = os.path.join(source_dir, "test_")
125164
cmd_str = f"no-args -d '{partial_name}'"
126165

127166
matches.Clear()
128167
descriptions.Clear()
129-
num_completions = interp.HandleCompletionWithDescriptions(cmd_str, len(cmd_str) - 1, 0,
130-
1000, matches, descriptions)
131-
print(f"First: {matches.GetStringAtIndex(0)}\nSecond: {matches.GetStringAtIndex(1)}\nThird: {matches.GetStringAtIndex(2)}")
168+
num_completions = interp.HandleCompletionWithDescriptions(
169+
cmd_str, len(cmd_str) - 1, 0, 1000, matches, descriptions
170+
)
171+
print(
172+
f"First: {matches.GetStringAtIndex(0)}\nSecond: {matches.GetStringAtIndex(1)}\nThird: {matches.GetStringAtIndex(2)}"
173+
)
132174
self.assertEqual(num_completions, 1, "Only one completion for source file")
133175
self.assertEqual(matches.GetSize(), 2, "The first element is the complete line")
134-
self.assertEqual(matches.GetStringAtIndex(0), "commands.py' ", "And we got the right extra characters")
135-
self.assertEqual(matches.GetStringAtIndex(1), test_file_path, "And we got the right match")
136-
self.assertEqual(descriptions.GetSize(), 2, "descriptions match the return length")
176+
self.assertEqual(
177+
matches.GetStringAtIndex(0),
178+
"commands.py' ",
179+
"And we got the right extra characters",
180+
)
181+
self.assertEqual(
182+
matches.GetStringAtIndex(1), test_file_path, "And we got the right match"
183+
)
184+
self.assertEqual(
185+
descriptions.GetSize(), 2, "descriptions match the return length"
186+
)
137187
# FIXME: we don't return descriptions for enum elements
138-
#self.assertEqual(descriptions.GetStringAtIndex(1), "does foo things", "And we got the right description")
139-
188+
# self.assertEqual(descriptions.GetStringAtIndex(1), "does foo things", "And we got the right description")
189+
140190
# Try a command with arguments.
141191
# FIXME: It should be enough to define an argument and it's type to get the completer
142192
# wired up for that argument type if it is a known type. But that isn't wired up in the
143193
# command parser yet, so I don't have any tests for that. We also don't currently check
144194
# that the arguments passed match the argument specifications, so here I just pass a couple
145195
# sets of arguments and make sure we get back what we put in:
146-
self.expect("two-args 'First Argument' 'Second Argument'", substrs=["0: First Argument", "1: Second Argument"])
196+
self.expect(
197+
"two-args 'First Argument' 'Second Argument'",
198+
substrs=["0: First Argument", "1: Second Argument"],
199+
)

0 commit comments

Comments
 (0)