diff options
author | Jonas Devlieghere <jonas@devlieghere.com> | 2023-05-25 08:48:57 -0700 |
---|---|---|
committer | Jonas Devlieghere <jonas@devlieghere.com> | 2023-05-25 12:54:09 -0700 |
commit | 2238dcc39358353cac21df75c3c3286ab20b8f53 (patch) | |
tree | 1bb7ec8d7405ccd7fdb5a8a78d0cf5ef40bcc963 /lldb/packages/Python/lldbsuite/test/lldbinline.py | |
parent | daeee56798c51e8f007e8e8e6e677a420b14c9ef (diff) | |
download | llvm-2238dcc39358353cac21df75c3c3286ab20b8f53.zip llvm-2238dcc39358353cac21df75c3c3286ab20b8f53.tar.gz llvm-2238dcc39358353cac21df75c3c3286ab20b8f53.tar.bz2 |
[NFC][Py Reformat] Reformat python files in lldb
This is an ongoing series of commits that are reformatting our Python
code. Reformatting is done with `black` (23.1.0).
If you end up having problems merging this commit because you have made
changes to a python file, the best way to handle that is to run `git
checkout --ours <yourfile>` and then reformat it with black.
RFC: https://discourse.llvm.org/t/rfc-document-and-standardize-python-code-style
Differential revision: https://reviews.llvm.org/D151460
Diffstat (limited to 'lldb/packages/Python/lldbsuite/test/lldbinline.py')
-rw-r--r-- | lldb/packages/Python/lldbsuite/test/lldbinline.py | 84 |
1 files changed, 42 insertions, 42 deletions
diff --git a/lldb/packages/Python/lldbsuite/test/lldbinline.py b/lldb/packages/Python/lldbsuite/test/lldbinline.py index e8d4d4d..6fb23ee 100644 --- a/lldb/packages/Python/lldbsuite/test/lldbinline.py +++ b/lldb/packages/Python/lldbsuite/test/lldbinline.py @@ -15,25 +15,25 @@ from . import configuration from . import lldbutil from .decorators import * + def source_type(filename): _, extension = os.path.splitext(filename) return { - '.c': 'C_SOURCES', - '.cpp': 'CXX_SOURCES', - '.cxx': 'CXX_SOURCES', - '.cc': 'CXX_SOURCES', - '.m': 'OBJC_SOURCES', - '.mm': 'OBJCXX_SOURCES' + ".c": "C_SOURCES", + ".cpp": "CXX_SOURCES", + ".cxx": "CXX_SOURCES", + ".cc": "CXX_SOURCES", + ".m": "OBJC_SOURCES", + ".mm": "OBJCXX_SOURCES", }.get(extension, None) class CommandParser: - def __init__(self): self.breakpoints = [] def parse_one_command(self, line): - parts = line.split('//%') + parts = line.split("//%") command = None new_breakpoint = True @@ -46,7 +46,7 @@ class CommandParser: def parse_source_files(self, source_files): for source_file in source_files: - file_handle = io.open(source_file, encoding='utf-8') + file_handle = io.open(source_file, encoding="utf-8") lines = file_handle.readlines() line_number = 0 # non-NULL means we're looking through whitespace to find @@ -62,30 +62,31 @@ class CommandParser: if command is not None: if current_breakpoint is None: current_breakpoint = {} - current_breakpoint['file_name'] = source_file - current_breakpoint['line_number'] = line_number - current_breakpoint['command'] = command + current_breakpoint["file_name"] = source_file + current_breakpoint["line_number"] = line_number + current_breakpoint["command"] = command self.breakpoints.append(current_breakpoint) else: - current_breakpoint['command'] = current_breakpoint[ - 'command'] + "\n" + command + current_breakpoint["command"] = ( + current_breakpoint["command"] + "\n" + command + ) for bkpt in self.breakpoints: - bkpt['command'] = textwrap.dedent(bkpt['command']) + bkpt["command"] = textwrap.dedent(bkpt["command"]) def set_breakpoints(self, target): for breakpoint in self.breakpoints: - breakpoint['breakpoint'] = target.BreakpointCreateByLocation( - breakpoint['file_name'], breakpoint['line_number']) + breakpoint["breakpoint"] = target.BreakpointCreateByLocation( + breakpoint["file_name"], breakpoint["line_number"] + ) def handle_breakpoint(self, test, breakpoint_id): for breakpoint in self.breakpoints: - if breakpoint['breakpoint'].GetID() == breakpoint_id: - test.execute_user_command(breakpoint['command']) + if breakpoint["breakpoint"].GetID() == breakpoint_id: + test.execute_user_command(breakpoint["command"]) return class InlineTest(TestBase): - def getBuildDirBasename(self): return self.__class__.__name__ + "." + self.testMethodName @@ -103,17 +104,17 @@ class InlineTest(TestBase): else: categories[t] = [f] - with open(makefilePath, 'w+') as makefile: + with open(makefilePath, "w+") as makefile: for t in list(categories.keys()): line = t + " := " + " ".join(categories[t]) makefile.write(line + "\n") - if ('OBJCXX_SOURCES' in list(categories.keys())) or \ - ('OBJC_SOURCES' in list(categories.keys())): - makefile.write( - "LDFLAGS = $(CFLAGS) -lobjc -framework Foundation\n") + if ("OBJCXX_SOURCES" in list(categories.keys())) or ( + "OBJC_SOURCES" in list(categories.keys()) + ): + makefile.write("LDFLAGS = $(CFLAGS) -lobjc -framework Foundation\n") - if ('CXX_SOURCES' in list(categories.keys())): + if "CXX_SOURCES" in list(categories.keys()): makefile.write("CXXFLAGS += -std=c++11\n") makefile.write("include Makefile.rules\n") @@ -135,8 +136,7 @@ class InlineTest(TestBase): def do_test(self): exe = self.getBuildArtifact("a.out") - source_files = [f for f in os.listdir(self.getSourceDir()) - if source_type(f)] + source_files = [f for f in os.listdir(self.getSourceDir()) if source_type(f)] target = self.dbg.CreateTarget(exe) parser = CommandParser() @@ -150,18 +150,19 @@ class InlineTest(TestBase): while lldbutil.get_stopped_thread(process, lldb.eStopReasonBreakpoint): hit_breakpoints += 1 - thread = lldbutil.get_stopped_thread( - process, lldb.eStopReasonBreakpoint) + thread = lldbutil.get_stopped_thread(process, lldb.eStopReasonBreakpoint) for bp_id in self._get_breakpoint_ids(thread): parser.handle_breakpoint(self, bp_id) process.Continue() - self.assertTrue(hit_breakpoints > 0, - "inline test did not hit a single breakpoint") + self.assertTrue( + hit_breakpoints > 0, "inline test did not hit a single breakpoint" + ) # Either the process exited or the stepping plan is complete. - self.assertTrue(process.GetState() in [lldb.eStateStopped, - lldb.eStateExited], - PROCESS_EXITED) + self.assertTrue( + process.GetState() in [lldb.eStateStopped, lldb.eStateExited], + PROCESS_EXITED, + ) def check_expression(self, expression, expected_result, use_summary=True): value = self.frame().EvaluateExpression(expression) @@ -173,8 +174,7 @@ class InlineTest(TestBase): answer = value.GetSummary() else: answer = value.GetValue() - report_str = "%s expected: %s got: %s" % ( - expression, expected_result, answer) + report_str = "%s expected: %s got: %s" % (expression, expected_result, answer) self.assertTrue(answer == expected_result, report_str) @@ -183,13 +183,12 @@ def ApplyDecoratorsToFunction(func, decorators): if isinstance(decorators, list): for decorator in decorators: tmp = decorator(tmp) - elif hasattr(decorators, '__call__'): + elif hasattr(decorators, "__call__"): tmp = decorators(tmp) return tmp -def MakeInlineTest(__file, __globals, decorators=None, name=None, - build_dict=None): +def MakeInlineTest(__file, __globals, decorators=None, name=None, build_dict=None): # Adjust the filename if it ends in .pyc. We want filenames to # reflect the source python file, not the compiled variant. if __file is not None and __file.endswith(".pyc"): @@ -203,8 +202,9 @@ def MakeInlineTest(__file, __globals, decorators=None, name=None, test_func = ApplyDecoratorsToFunction(InlineTest._test, decorators) # Build the test case - test_class = type(name, (InlineTest,), dict(test=test_func, - name=name, _build_dict=build_dict)) + test_class = type( + name, (InlineTest,), dict(test=test_func, name=name, _build_dict=build_dict) + ) # Add the test case to the globals, and hide InlineTest __globals.update({name: test_class}) |