示例#1
0
def test_static_color_methods():
    """Test all convenience methods."""
    assert Color('{autored}this is a test.{/autored}') == Color.red('this is a test.', auto=True)
    assert Color('{red}this is a test.{/red}') == Color.red('this is a test.')
    assert Color('{autobgred}this is a test.{/autobgred}') == Color.bgred('this is a test.', auto=True)
    assert Color('{bgred}this is a test.{/bgred}') == Color.bgred('this is a test.')
    assert Color('{autogreen}this is a test.{/autogreen}') == Color.green('this is a test.', auto=True)
    assert Color('{green}this is a test.{/green}') == Color.green('this is a test.')
    assert Color('{autobggreen}this is a test.{/autobggreen}') == Color.bggreen('this is a test.', auto=True)
    assert Color('{bggreen}this is a test.{/bggreen}') == Color.bggreen('this is a test.')
    assert Color('{autoblue}this is a test.{/autoblue}') == Color.blue('this is a test.', auto=True)
    assert Color('{blue}this is a test.{/blue}') == Color.blue('this is a test.')
    assert Color('{autobgblue}this is a test.{/autobgblue}') == Color.bgblue('this is a test.', auto=True)
    assert Color('{bgblue}this is a test.{/bgblue}') == Color.bgblue('this is a test.')
    assert Color('{autogreen}this is a test.{/autogreen}') == Color.green('this is a test.', auto=True)
    assert Color('{green}this is a test.{/green}') == Color.green('this is a test.')
    assert Color('{autobggreen}this is a test.{/autobggreen}') == Color.bggreen('this is a test.', auto=True)
    assert Color('{bggreen}this is a test.{/bggreen}') == Color.bggreen('this is a test.')
    assert Color('{autoyellow}this is a test.{/autoyellow}') == Color.yellow('this is a test.', auto=True)
    assert Color('{yellow}this is a test.{/yellow}') == Color.yellow('this is a test.')
    assert Color('{autobgyellow}this is a test.{/autobgyellow}') == Color.bgyellow('this is a test.', auto=True)
    assert Color('{bgyellow}this is a test.{/bgyellow}') == Color.bgyellow('this is a test.')
    assert Color('{autocyan}this is a test.{/autocyan}') == Color.cyan('this is a test.', auto=True)
    assert Color('{cyan}this is a test.{/cyan}') == Color.cyan('this is a test.')
    assert Color('{autobgcyan}this is a test.{/autobgcyan}') == Color.bgcyan('this is a test.', auto=True)
    assert Color('{bgcyan}this is a test.{/bgcyan}') == Color.bgcyan('this is a test.')
    assert Color('{automagenta}this is a test.{/automagenta}') == Color.magenta('this is a test.', auto=True)
    assert Color('{magenta}this is a test.{/magenta}') == Color.magenta('this is a test.')
    assert Color('{autobgmagenta}this is a test.{/autobgmagenta}') == Color.bgmagenta('this is a test.', auto=True)
    assert Color('{bgmagenta}this is a test.{/bgmagenta}') == Color.bgmagenta('this is a test.')
示例#2
0
class MonitorResults(object):
    columns = OrderedDict([
        ('Name', itemgetter('name')),
        ('Status', lambda x: Color.red('FAIL')
         if x['fail'] else Color.green('OK')),
        ('Since', lambda x: human_since(x['since'], True)),
        ('Updated', lambda x: human_since(x['updated_at'], True)),
        ('Times', lambda x: str(x['executions'])),
    ])

    def __init__(self, monitor_name, monitor_results, sma=None):
        self.monitor_name = monitor_name
        self.monitor_results = monitor_results
        self.sma = sma

    def get_section(self):
        return self.monitor_name

    def get_results_columns(self, columns=None):
        for name, result in self.monitor_results.items():
            result = dict(result)
            result['name'] = name
            yield [fn(result) for fn in self.columns.values()]

    def __str__(self):
        return '{}\n'.format(UnixTable(list(self.get_results_columns())).table)
示例#3
0
def test_all(image_output=False, container_output=False):
    results = []
    for dirname in os.listdir(__dir__):
        if not os.path.isdir(dirname):
            continue
        try:
            test_image(dirname, image_output=image_output, container_output=container_output)
        except ChildProcessError:
            results.append(False)
        else:
            results.append(True)
    print('-' * 60)
    print('PASSED: {} {}/{}'.format(
        ''.join([{False: Color.red('F'), True: Color.green('.')}[x] for x in results]),
        len(list(filter(lambda x: x, results))), len(results)
    ))
示例#4
0
def test_all(image_output=False, container_output=False):
    results = []
    for dirname in os.listdir(__dir__):
        if not os.path.isdir(dirname):
            continue
        try:
            test_image(dirname,
                       image_output=image_output,
                       container_output=container_output)
        except ChildProcessError:
            results.append(False)
        else:
            results.append(True)
    print('-' * 60)
    print('PASSED: {} {}/{}'.format(
        ''.join([{
            False: Color.red('F'),
            True: Color.green('.')
        }[x] for x in results]), len(list(filter(lambda x: x, results))),
        len(results)))