Beispiel #1
0
    def test_format_line(self):

        cases = (
            (([], '', ''), '', ''),
            ((['a'], '', ''), 'a', ''),
            (([['a', 'bc']], '', ''), ' a\n'
             'bc', 'default alignment is to right'),
            (([['a', 'bc'], 'foo'], '', ''), ' afoo\n'
             'bc   ', 'no sep, add space to align'),
            (([['a', 'bc'], 'foo'], '|', ''), ' a|foo\n'
             'bc|   ', 'sep is "|"'),
            (([['a', 'bc'], 'foo', [1, 2, 333]], '|', ''), ' a|foo|  1\n'
             'bc|   |  2\n'
             '  |   |333', 'number will be convert to str'),
            (([['a', 'bc'], 'foo',
               [1, 2, strutil.blue('xp')]], '|', ''), ' a|foo| 1\n'
             'bc|   | 2\n'
             '  |   |' + str(strutil.blue('xp')),
             'strutil.ColoredString instance is compatible'),
        )

        for _in, _out, _mes in cases:

            rst = strutil.format_line(*_in)

            dd("_in: " + str(_in))
            dd("rst:\n" + rst)

            self.assertEqual(_out, rst,
                             ('input: {_in}, output: {_out}, expected: {rst},'
                              ' message: {_mes}').format(_in=repr(_in),
                                                         _out=repr(_out),
                                                         rst=repr(rst),
                                                         _mes=_mes))
    def test_named_color(self):

        print

        # named color shortcuts
        print strutil.blue('blue'),
        print strutil.cyan('cyan'),
        print strutil.green('green'),
        print strutil.yellow('yellow'),
        print strutil.red('red'),
        print strutil.purple('purple'),
        print strutil.white('white'),
        print

        print strutil.danger('danger'),
        print strutil.warn('warn'),
        print strutil.loaded('loaded'),
        print strutil.normal('normal'),
        print strutil.optimal('optimal'),
        print
Beispiel #3
0
    def test_named_color(self):

        print

        # named color shortcuts
        print strutil.blue('blue'),
        print strutil.cyan('cyan'),
        print strutil.green('green'),
        print strutil.yellow('yellow'),
        print strutil.red('red'),
        print strutil.purple('purple'),
        print strutil.white('white'),
        print

        print strutil.danger('danger'),
        print strutil.warn('warn'),
        print strutil.loaded('loaded'),
        print strutil.normal('normal'),
        print strutil.optimal('optimal'),
        print
Beispiel #4
0
    str_split += ' algorithm is applied: runs of consecutive whitespace'
    str_split += ' are regarded as a single separator'
    str_split = strutil.ColoredString(str_split, 'red')
    list_split = str_split.split()
    for v in list_split:
        print v

    for v in strutil.ColoredString('h\rello\npyk\rit').splitlines():
        print v
    
    str_break_line = 'one two three four five six seven eight nine ten'
    print strutil.break_line(str_break_line, 10)
    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")