Example #1
0
 def test(c):
     opts = TestConfig(wrap_column=c.wid, indent=c.ind)
     text = Text(c.text)
     sel = (0, len(c.text))
     ctok = c.comment if c.ind else None
     output = "\n".join(wraplines(iterlines(text, sel), opts, ctok))
     eq_(output, c.result)
Example #2
0
 def test(c):
     m = Mocker()
     tv = m.mock(TextView)
     if c.ind:
         tv.doc_view.document.comment_token >> c.comment
     opts = TestConfig(wrap_column=c.wid, indent=c.ind)
     text = fn.NSString.stringWithString_(c.text)
     sel = (0, len(c.text))
     with m:
         if c._get("debug", False):
             import pdb; pdb.set_trace()
         output = "\n".join(wraplines(iterlines(text, sel), opts, tv))
         eq_(c.result, output)
Example #3
0
 def test(c):
     m = Mocker()
     tv = m.mock(TextView)
     if c.ind:
         tv.doc_view.document.comment_token >> c.comment
     opts = TestConfig(wrap_column=c.wid, indent=c.ind)
     text = fn.NSString.stringWithString_(c.text)
     sel = (0, len(c.text))
     with m:
         if c._get("debug", False):
             import pdb
             pdb.set_trace()
         output = "\n".join(wraplines(iterlines(text, sel), opts, tv))
         eq_(c.result, output)
Example #4
0
def pretty_format(obj, indent=0, width=72):
    rep = repr(obj)
    if len(rep) < width - indent and not rep.startswith("#") and "# " not in rep:
        return rep
    if isinstance(obj, list) and all(isinstance(x, str) and " " not in x for x in obj):
        indent += 4
        lines = iter([' ' * indent + " ".join(obj)])
        opts = DictObj(wrap_column=width, indent=True)
        return '"""\n{items}{indent}""".split()'.format(
            indent=' ' * indent,
            items="\n".join(wraplines(lines, opts))
        )
    if type(obj) in ITEM_FORMATS:
        return format_items(obj, indent, width)
    return rep