Beispiel #1
0
    def test_line_pad(self):

        cases = (
            (('', ''), '', ''),
            (('a', ''), 'a', ''),
            (('a', ' '), ' a', ''),
            (('a', '   '), '   a', ''),
            (('a\nb', '   '), '   a\n'
             '   b', ''),
            (('a\nbc', lambda line: 'x' * len(line)), 'xa\n'
             'xxbc', ''),
        )

        for _in, _out, _mes in cases:
            rst = strutil.line_pad(*_in)
            self.assertEqual(_out, rst,
                             ('input: {_in}, output: {_out}, expected: {rst},'
                              ' message: {_mes}').format(_in=repr(_in),
                                                         _out=repr(_out),
                                                         rst=repr(rst),
                                                         _mes=_mes))
Beispiel #2
0
    str_break_line = 'aaaaabbbbbcccccdddddeeeeefffff'
    print strutil.break_line(str_break_line, 10)

    t = strutil.blue("blue-text")
    print t

    for p in xrange(0, 200):
        print strutil.colorize(p, 100),
    print 
    for p in xrange(0, 100):
        print strutil.colorize(p, 10),
    print
    print strutil.colorize(22, 100, '{0:>10}%')
    
    str_linestr = 'adw\nni\nleng\n'
    print strutil.line_pad(str_linestr, 'hehe' * 4)

    print strutil.format_line([["name:", "age:"], ["drdrxp", "18"], "wow"], sep= 
    " | ", aligns="lll")

    lines = 'cheng yang 180'
    lines += 'zhang xixi 150'
    lines += 'liu xiang 170'
    lines += 'yao ming 160'
    print strutil.sharding(lines, size=160, accuracy=30)
    
    a = [1, 2, 3, 4, 5, 6, 7, 8]
    for l in strutil.struct_repr(a):
        print l
    print