From 05882029beac3d19241c8949806dbdb035421c0d Mon Sep 17 00:00:00 2001 From: Vrishn Viswa Sathyamoorthy Date: Wed, 2 Dec 2026 10:24:59 -0500 Subject: [PATCH] Restore Windows benchmark comparison tables with ASCII borders Assisted-by: OpenAI Codex (GPT-6) --- .../amazon/ionbenchmark/ion_benchmark_cli.py | 7 ++-- tests/test_benchmark_cli.py | 41 ++++++++++++++++++- 2 files changed, 44 insertions(+), 4 deletions(-) diff --git a/src-python/amazon/ionbenchmark/ion_benchmark_cli.py b/src-python/amazon/ionbenchmark/ion_benchmark_cli.py index 412173aec..087193c80 100644 --- a/src-python/amazon/ionbenchmark/ion_benchmark_cli.py +++ b/src-python/amazon/ionbenchmark/ion_benchmark_cli.py @@ -111,9 +111,10 @@ def compare_command(): with open(output_file_for_comparison, 'bw') as o: ion.dump(report, o, binary=False) - # Disabled tabulate method on Windows due to the issue#307 - https://github.com/amazon-ion/ion-python/issues/307 - if not args['--quiet'] and platform.system() != 'Windows': - print(tabulate(report, tablefmt='fancy_grid', headers='keys')) + if not args['--quiet']: + # Use ASCII borders for Windows consoles with legacy encodings. + tablefmt = 'grid' if platform.system() == 'Windows' else 'fancy_grid' + print(tabulate(report, tablefmt=tablefmt, headers='keys')) if has_regression: if args['--fail']: diff --git a/tests/test_benchmark_cli.py b/tests/test_benchmark_cli.py index 9d948b53a..536fc6fae 100644 --- a/tests/test_benchmark_cli.py +++ b/tests/test_benchmark_cli.py @@ -1,10 +1,15 @@ +import io import os +import sys import time from os.path import abspath, join, dirname +from pathlib import Path + +import pytest from amazon.ion import simpleion from amazon.ion.equivalence import ion_equals -from amazon.ionbenchmark import Format, benchmark_spec +from amazon.ionbenchmark import Format, benchmark_spec, ion_benchmark_cli from amazon.ionbenchmark.Format import format_is_ion, format_is_cbor, format_is_json, rewrite_file_to_format from amazon.ionbenchmark.benchmark_spec import BenchmarkSpec from amazon.ionbenchmark.ion_benchmark_cli import TOOL_VERSION @@ -233,3 +238,37 @@ def test_multiple_top_level_values(args): (error_code, _, _) = run_cli([f'{command}', file, '--format', f'{format_option}', '--io-type', 'file']) assert not error_code + +@pytest.mark.parametrize('system, encoding', [('Windows', 'cp1252'), ('Linux', 'utf-8')]) +@pytest.mark.parametrize('quiet', [False, True]) +@pytest.mark.parametrize('regression', [False, True]) +def test_compare_table_output(monkeypatch, system, encoding, quiet, regression): + fixtures = Path(__file__).parent / 'benchmark_sample_data' / 'compare' + previous = fixtures / 'cats_baseline.ion' + current = fixtures / ('cats_large_regression.ion' if regression else 'cats_baseline.ion') + args = ['ion_benchmark_cli.py', 'compare', str(previous), str(current), '--fail'] + if quiet: + args.append('--quiet') + monkeypatch.setattr(sys, 'argv', args) + monkeypatch.setattr(ion_benchmark_cli.platform, 'system', lambda: system) + buffer = io.BytesIO() + stream = io.TextIOWrapper(buffer, encoding=encoding) + monkeypatch.setattr(sys, 'stdout', stream) + + if regression: + with pytest.raises(SystemExit, match='One or more regressions detected'): + ion_benchmark_cli.compare_command() + else: + ion_benchmark_cli.compare_command() + stream.flush() + output = buffer.getvalue().decode(encoding) + if quiet: + assert output == '' + else: + assert 'file_size(B)' in output + assert 'time_mean(ns)' in output + assert '(ion_text,loads,cat.ion)' in output + if system == 'Windows': + assert '+-' in output + else: + assert '\u2552' in output