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
This commit is contained in:
Jesse Yurkovich
2025-08-04 19:18:16 +02:00
committed by Jesse Yurkovich
parent efef8a201a
commit da1846ebe1

View File

@@ -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")