output_printer.py 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. # Copyright Materialize, Inc. and contributors. All rights reserved.
  2. #
  3. # Use of this software is governed by the Business Source License
  4. # included in the LICENSE file at the root of this repository.
  5. #
  6. # As of the Change Date specified in that file, in accordance with
  7. # the Business Source License, use of this software will be governed
  8. # by the Apache License, Version 2.0.
  9. import sys
  10. from materialize.output_consistency.common.configuration import (
  11. ConsistencyTestConfiguration,
  12. )
  13. from materialize.output_consistency.execution.query_output_mode import (
  14. QueryOutputMode,
  15. )
  16. from materialize.output_consistency.input_data.test_input_data import (
  17. ConsistencyTestInputData,
  18. )
  19. from materialize.output_consistency.output.base_output_printer import (
  20. BaseOutputPrinter,
  21. OutputPrinterMode,
  22. )
  23. from materialize.output_consistency.output.reproduction_code_printer import (
  24. ReproductionCodePrinter,
  25. )
  26. from materialize.output_consistency.status.test_summary import ConsistencyTestSummary
  27. from materialize.output_consistency.validation.validation_message import ValidationError
  28. class OutputPrinter(BaseOutputPrinter):
  29. def __init__(
  30. self,
  31. input_data: ConsistencyTestInputData,
  32. query_output_mode: QueryOutputMode,
  33. print_mode: OutputPrinterMode = OutputPrinterMode.PRINT,
  34. ):
  35. super().__init__(print_mode=print_mode)
  36. self.reproduction_code_printer = ReproductionCodePrinter(
  37. input_data, query_output_mode
  38. )
  39. def print_sql(self, sql: str) -> None:
  40. self._print_executable(sql)
  41. self.print_empty_line()
  42. def print_non_executable_sql(self, sql: str) -> None:
  43. self._print_text(sql)
  44. def print_info(self, text: str) -> None:
  45. self._print_text(text)
  46. def print_error(self, error_message: str) -> None:
  47. self._print_text(error_message)
  48. def print_test_summary(self, summary: ConsistencyTestSummary) -> None:
  49. self.start_section("Test summary", collapsed=False)
  50. self._print_text(summary.get())
  51. self.start_section("Operation and function statistics", collapsed=True)
  52. self._print_text(summary.get_function_and_operation_stats())
  53. self.start_section("Used ignore entries", collapsed=True)
  54. self._print_text(summary.format_used_ignore_entries())
  55. def print_status(self, status_message: str) -> None:
  56. self._print_text(status_message)
  57. def print_config(self, config: ConsistencyTestConfiguration) -> None:
  58. config_properties = vars(config)
  59. self.start_section("Configuration", collapsed=False)
  60. self._print_text(
  61. "\n".join(f" {item[0]} = {item[1]}" for item in config_properties.items())
  62. )
  63. self.print_empty_line()
  64. def print_reproduction_code(self, errors: list[ValidationError]) -> None:
  65. self.reproduction_code_printer.print_reproduction_code(errors)
  66. def flush(self) -> None:
  67. sys.stdout.flush()