How to use _indent_with method in Slash

Best Python code snippet using slash

console_reporter.py

Source:console_reporter.py Github

copy

Full Screen

...236 frame, include_context=(console_traceback_level >= ALL_FRAMES_WITH_CONTEXT))237 if frame_iteration.last:238 self._terminal.write(err_type, **theme('tb-error'))239 self._terminal.write(240 self._indent_with(err.message, 4), **theme('tb-error'))241 self._terminal.write('\n')242 def _report_additional_test_details(self, result):243 if result.is_success():244 return245 detail_items = result.details.all().items()246 log_path = result.get_log_path()247 if log_path is not None:248 detail_items = itertools.chain(detail_items, [('Log', log_path)])249 for index, (key, value) in enumerate(detail_items):250 if index == 0:251 self._terminal.write(' - Additional Details:\n', **theme('test-additional-details-header'))252 self._terminal.write(' > {}: {!r}\n'.format(key, value), **theme('test-additional-details'))253 def _indent_with(self, text, indent):254 if isinstance(indent, int):255 indent = ' ' * indent256 return '\n'.join(indent + line for line in text.splitlines())257 def _report_result_skip_summary(self, result):258 msg = '\tSkipped'259 skip_reasons = [r for r in result.get_skips() if r is not None]260 if skip_reasons:261 msg += ' ({})'.format(', '.join(skip_reasons))262 msg += '\n'263 self._terminal.write(msg, **theme('test-skip-message'))264 def _write_frame_locals(self, frame):265 with vintage.get_no_deprecations_context():266 locals = frame.locals267 globals = frame.globals...

Full Screen

Full Screen

tree_printer.py

Source:tree_printer.py Github

copy

Full Screen

1"""This is a really dirty script that is used to dump the AST.2"""3import ast4from py2c.tree import Node, iter_fields as py_iter_fields5import py2c.tree.python as py_tree6class Indentor(object):7 """A simple class to manage indents8 """9 def __init__(self, indent_with=' '):10 self.indent = ""11 self._indent_with = indent_with12 self.skip = False13 def should_skip_next(self, should=True):14 self.skip = should15 def __enter__(self):16 self.indent = self.indent + self._indent_with17 def __exit__(self, *args):18 self.indent = self.indent[:-len(self._indent_with)]19 def __str__(self):20 if self.skip:21 self.skip = False22 return ""23 else:24 return self.indent25def write(*args, sep="", end=""):26 print(*args, sep=sep, end=end)27def _dump(node, indentor):28 if isinstance(node, (list, tuple)):29 _dump_list(node, indentor)30 elif isinstance(node, (Node, ast.AST)):31 _dump_node(node, indentor)32 else:33 write(indentor, repr(node))34def _dump_list(li, indentor):35 if not li:36 write("[]")37 indentor.skip = False38 else:39 length = len(li)40 write("[")41 for i, elem in enumerate(li):42 with indentor:43 write("\n")44 indentor.skip = False45 _dump(elem, indentor)46 if i < length - 1:47 write(",")48 should_skip = indentor.skip49 write("\n", indentor, "]")50 indentor.skip = should_skip51def _dump_node(node, indentor):52 # Initial header53 if isinstance(node, Node):54 module = "py_tree"55 iter_fields = py_iter_fields56 else:57 module = "ast"58 iter_fields = ast.iter_fields59 write(indentor, "{}.{}(".format(module, node.__class__.__name__))60 # Should the node be printed inline61 in_line = isinstance(node, (py_tree.Name, ast.Name, ast.NameConstant))62 length = len(node._fields)63 for i, (name, value) in enumerate(iter_fields(node)):64 with indentor:65 if in_line:66 indentor.skip = True67 else:68 write("\n")69 write(indentor, name, "=")70 indentor.skip = True71 _dump(value, indentor)72 if i < length - 1:73 write(",")74 if in_line:75 write(" ")76 if not in_line and node._fields:77 write("\n", indentor, ")",)78 else:79 write(")")80# -----------------------------------------------------------------------------81# The whole point of the stuff above82# -----------------------------------------------------------------------------83def dump_ast(node, indent_with=" "):84 return _dump(node, Indentor())85# def main():86# import textwrap87# dump_ast(ast.parse(textwrap.dedent("""88# """)))89# if __name__ == '__main__':...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Slash automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful