def test_table_formatting(): benchmark = {'params': [], 'param_names': [], 'unit': 's'} result = [] expected = ["[]"] assert benchmarks._format_benchmark_result(result, benchmark) == expected benchmark = { 'params': [['a', 'b', 'c']], 'param_names': ['param1'], "unit": "seconds" } result = list(zip([1e-6, 2e-6, 3e-6], [3e-6, 2e-6, 1e-6])) expected = ("======== ==========\n" " param1 \n" "-------- ----------\n" " a 1.00\u00b13\u03bcs \n" " b 2.00\u00b12\u03bcs \n" " c 3.00\u00b11\u03bcs \n" "======== ==========") table = "\n".join( benchmarks._format_benchmark_result(result, benchmark, max_width=80)) assert table == expected benchmark = { 'params': [["'a'", "'b'", "'c'"], ["[1]", "[2]"]], 'param_names': ['param1', 'param2'], "unit": "seconds" } result = list(zip([1, 2, None, 4, 5, float('nan')], [None] * 6)) expected = ("======== ======== =======\n" "-- param2 \n" "-------- ----------------\n" " param1 [1] [2] \n" "======== ======== =======\n" " a 1.00s 2.00s \n" " b failed 4.00s \n" " c 5.00s n/a \n" "======== ======== =======") table = "\n".join( benchmarks._format_benchmark_result(result, benchmark, max_width=80)) assert table == expected expected = ("======== ======== ========\n" " param1 param2 \n" "-------- -------- --------\n" " a [1] 1.00s \n" " a [2] 2.00s \n" " b [1] failed \n" " b [2] 4.00s \n" " c [1] 5.00s \n" " c [2] n/a \n" "======== ======== ========") table = "\n".join( benchmarks._format_benchmark_result(result, benchmark, max_width=0)) assert table == expected
def test_table_formatting(): benchmark = {'params': [], 'param_names': [], 'unit': 's'} result = [] expected = ["[]"] assert benchmarks._format_benchmark_result(result, benchmark) == expected benchmark = {'params': [['a', 'b', 'c']], 'param_names': ['param1'], "unit": "seconds"} result = list(zip([1e-6, 2e-6, 3e-6], [3e-6, 2e-6, 1e-6])) expected = ("======== ==========\n" " param1 \n" "-------- ----------\n" " a 1.00\u00b13\u03bcs \n" " b 2.00\u00b12\u03bcs \n" " c 3.00\u00b11\u03bcs \n" "======== ==========") table = "\n".join(benchmarks._format_benchmark_result(result, benchmark, max_width=80)) assert table == expected benchmark = {'params': [["'a'", "'b'", "'c'"], ["[1]", "[2]"]], 'param_names': ['param1', 'param2'], "unit": "seconds"} result = list(zip([1, 2, None, 4, 5, float('nan')], [None]*6)) expected = ("======== ======== =======\n" "-- param2 \n" "-------- ----------------\n" " param1 [1] [2] \n" "======== ======== =======\n" " a 1.00s 2.00s \n" " b failed 4.00s \n" " c 5.00s n/a \n" "======== ======== =======") table = "\n".join(benchmarks._format_benchmark_result(result, benchmark, max_width=80)) assert table == expected expected = ("======== ======== ========\n" " param1 param2 \n" "-------- -------- --------\n" " a [1] 1.00s \n" " a [2] 2.00s \n" " b [1] failed \n" " b [2] 4.00s \n" " c [1] 5.00s \n" " c [2] n/a \n" "======== ======== ========") table = "\n".join(benchmarks._format_benchmark_result(result, benchmark, max_width=0)) assert table == expected