From da1846ebe105648a71d9bf57af2bb40f4cd54417 Mon Sep 17 00:00:00 2001 From: Jesse Yurkovich Date: Mon, 4 Aug 2025 19:18:16 +0200 Subject: [PATCH] Tests: Add options controlling verbosity of output for IO report Add two sets of options to the IO Report class that allows tests to control the verbosity of output. - Add `Report.context_lines` controlling how many lines of context the diff uses when there are failures (3 by default) - Add `Report.side_to_print_single_line` (5 by default) and `Report.side_to_print_multi_line` (3 by default) controlling how many items are written out The first option helps when a failure in the test might not produce enough lines of output to know which object is affected. The second set of options allows individual tests to ensure more values are taken into consideration for test validation. They are exposed as class variables due to all the inner methods using them being static. Pull Request: https://projects.blender.org/blender/blender/pulls/143922 --- tests/python/modules/io_report.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/tests/python/modules/io_report.py b/tests/python/modules/io_report.py index 14b4d40709f..195cd03db2d 100644 --- a/tests/python/modules/io_report.py +++ b/tests/python/modules/io_report.py @@ -59,6 +59,10 @@ class Report: 'update_templates', ) + context_lines = 3 + side_to_print_single_line = 5 + side_to_print_multi_line = 3 + def __init__( self, title: str, @@ -211,7 +215,7 @@ integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw def _colored_diff(a: str, b: str): a_lines = a.splitlines() b_lines = b.splitlines() - diff = difflib.unified_diff(a_lines, b_lines, lineterm='') + diff = difflib.unified_diff(a_lines, b_lines, lineterm='', n=Report.context_lines) html = [] for line in diff: if line.startswith('+++') or line.startswith('---'): @@ -291,7 +295,7 @@ integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw @staticmethod def _write_collection_single(col, desc: StringIO) -> None: desc.write(f" - ") - side_to_print = 5 + side_to_print = Report.side_to_print_single_line if len(col) <= side_to_print * 2: for val in col: desc.write(f"{Report._val_to_str(val)} ") @@ -306,7 +310,7 @@ integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw # multi-line dump of head/tail @staticmethod def _write_collection_multi(col, desc: StringIO) -> None: - side_to_print = 3 + side_to_print = Report.side_to_print_multi_line if len(col) <= side_to_print * 2: for val in col: desc.write(f" - {Report._val_to_str(val)}\n")