How to use prettytable - 10 common examples

To help you get started, we’ve selected a few prettytable examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github skjerns / AutoSleepScorerDev / tools.py View on Github external
def print_string(results_dict):
    """ 
    creates an easy printable string from a results dict
    """
    max_hlen = 42
    hlen  =  7 + len('  '.join(list(results_dict)))
    maxlen = (max_hlen-7) //  len(results_dict) -2
    table = prettytable.PrettyTable(header=True, vrules=prettytable.NONE)
    table.border = False
    table.padding_width = 1
    cv = True if  type(results_dict[list(results_dict.keys())[0]][0]) is list else False
    if cv:
        table.add_column('', ['VAcc', 'V-F1', 'TAcc', 'T-F1'])
    else:
        table.add_column('', ['CAcc', 'C-F1', 'RAcc', 'R-F1'])

    for exp in results_dict:
        res = results_dict[exp]
        scores = []
        if cv:
            for fold in res:
                scores.append(fold[:4])
            scores = np.mean(scores,0)
        else:
github kxxoling / PTable / tests / test_prettytable.py View on Github external
def testMaxTableWidthIsTheLawWhenMinColumnWidthSetForSomeColumns(self):
        max_width = 40
        t = PrettyTable(max_table_width=max_width)
        t.field_names = ['tag', 'versions']
        versions = [
            'python/django-appconf:1.0.1',
            'python/django-braces:1.8.1',
            'python/django-compressor:2.0',
            'python/django-debug-toolbar:1.4',
            'python/django-extensions:1.6.1',
        ]
        t.add_row(['allmychanges.com', ', '.join(versions)])

        # Now, we'll set min width for first column
        # to not wrap it's content
        t._min_width['tag'] = len('allmychanges.com')

        result = t.get_string(hrules=ALL)
        lines = result.strip().split('\n')
github scaleway / natasha / test / func / func.py View on Github external
def run_tests(tests, log, config):
    """ Run test wrapper."""

    table = PrettyTable(['Test', 'Result'])
    for test_name in tests:
        if test_name == 'all':
            for _, conf in UNIT_TESTS.iteritems():
                test = conf['class'](conf['name'], log, config,
                                     conf['bpfilter'],
                                     count=conf['count'],
                                     payload=conf['payload'],
                                     local_sniff=conf['local_sniff'])
                result = test.run()
                table.add_row([conf['name'],
                               'Succeeded' if result else 'Failed'])
        else:
            conf = UNIT_TESTS[test_name]
            test = conf['class'](conf['name'], log, config,
                                 conf['bpfilter'],
                                 count=conf['count'],
github kxxoling / PTable / tests / test_prettytable.py View on Github external
def setUp(self):
        BasicTests.setUp(self)
        self.x.hrules = ALL
github columbia / fairtest / src / fairtest / modules / bug_report / report.py View on Github external
Pretty-print a contingency table

    Parameters
    ----------
    ct :
        the contingency table

    Returns
    -------
    pretty_table :
        a fancier string representation of the table
    """
    output = StringIO()
    rich_ct(ct).to_csv(output)
    output.seek(0)
    pretty_table = prettytable.from_csv(output)
    pretty_table.padding_width = 0
    pretty_table.align = 'r'
    pretty_table.align[pretty_table.field_names[0]] = 'l'
    return pretty_table
github columbia / fairtest / src_new_api / fairtest / bugreport / clustering / display_clusters.py View on Github external
def pretty_ct(ct):
    output = StringIO()
    rich_ct(ct).to_csv(output)
    output.seek(0)
    pretty_table = prettytable.from_csv(output)
    pretty_table.padding_width = 0
    pretty_table.align = 'r'
    pretty_table.align[pretty_table.field_names[0]] = 'l'
    return pretty_table
github columbia / fairtest / src / fairtest / bugreport / clustering / display_clusters.py View on Github external
def pretty_ct(ct):
    output = StringIO()
    rich_ct(ct).to_csv(output)
    output.seek(0)
    pretty_table = prettytable.from_csv(output)
    pretty_table.padding_width = 0
    pretty_table.align = 'r'
    pretty_table.align[pretty_table.field_names[0]] = 'l'
    return pretty_table
github kxxoling / PTable / tests / test_prettytable.py View on Github external
def setUp(self):
        csv_string = """City name, Area , Population , Annual Rainfall
        Sydney, 2058 ,  4336374   ,      1214.8
        Melbourne, 1566 ,  3806092   ,       646.9
        Brisbane, 5905 ,  1857594   ,      1146.4
        Perth, 5386 ,  1554769   ,       869.4
        Adelaide, 1295 ,  1158259   ,       600.5
        Hobart, 1357 ,   205556   ,       619.5
        Darwin, 0112 ,   120900   ,      1714.7"""
        csv_fp = StringIO.StringIO(csv_string)
        self.x = from_csv(csv_fp)
github kxxoling / PTable / tests / test_prettytable.py View on Github external
def testHrulesNone(self):
        default = self.x.get_string()
        override = self.x.get_string(hrules=NONE)
        self.assertTrue(default != override)
github ARMmbed / mbed-os / tools / test_api.py View on Github external
""" Prints test specification configuration passed to test script for verboseness
    """
    toolchains_info_cols = []
    # We need to check all toolchains for each device
    for k in json_data:
        # k should be 'targets'
        targets = json_data[k]
        for target in targets:
            toolchains = targets[target]
            for toolchain in toolchains:
                if toolchain not in toolchains_info_cols:
                    toolchains_info_cols.append(toolchain)

    # Prepare pretty table object to display test specification
    pt_cols = ["mcu"] + sorted(toolchains_info_cols)
    pt = PrettyTable(pt_cols, junction_char="|", hrules=HEADER)
    for col in pt_cols:
        pt.align[col] = "l"

    # { target : [conflicted toolchains] }
    toolchain_conflicts = {}
    toolchain_path_conflicts = []
    for k in json_data:
        # k should be 'targets'
        targets = json_data[k]
        for target in targets:
            target_supported_toolchains = get_target_supported_toolchains(target)
            if not target_supported_toolchains:
                target_supported_toolchains = []
            target_name = target if target in TARGET_MAP else "%s*"% target
            row = [target_name]
            toolchains = targets[target]