From b9bff5897df2a521b217a0aceb0eeeaf17100238 Mon Sep 17 00:00:00 2001 From: John Pennycook Date: Fri, 24 Jan 2025 11:24:20 +0000 Subject: [PATCH] Add test of summary report Signed-off-by: John Pennycook --- tests/report/__init__.py | 0 tests/report/test_summary_report.py | 52 +++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 tests/report/__init__.py create mode 100644 tests/report/test_summary_report.py diff --git a/tests/report/__init__.py b/tests/report/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/report/test_summary_report.py b/tests/report/test_summary_report.py new file mode 100644 index 0000000..7aeffc8 --- /dev/null +++ b/tests/report/test_summary_report.py @@ -0,0 +1,52 @@ +# Copyright (C) 2019-2024 Intel Corporation +# SPDX-License-Identifier: BSD-3-Clause + +import logging +import unittest +from io import StringIO + +from codebasin.report import summary + + +class TestSummaryReport(unittest.TestCase): + """ + Test summary report functionality. + """ + + def setUp(self): + logging.disable() + + def test_output(self): + """Check summary report output""" + setmap = { + frozenset(["X"]): 1, + frozenset(["Y"]): 2, + frozenset(["X", "Y"]): 3, + frozenset([]): 6, + } + output = StringIO() + summary(setmap, stream=output) + expected = """ +Summary +======= +┌────────────────┬───────┬─────────┐ +│ Platform Set │ LOC │ % LOC │ +├────────────────┼───────┼─────────┤ +│ {} │ 6 │ 50.00 │ +├────────────────┼───────┼─────────┤ +│ {X} │ 1 │ 8.33 │ +├────────────────┼───────┼─────────┤ +│ {Y} │ 2 │ 16.67 │ +├────────────────┼───────┼─────────┤ +│ {X, Y} │ 3 │ 25.00 │ +└────────────────┴───────┴─────────┘ +Code Divergence: 0.50 +Code Utilization: 0.38 +Unused Code (%): 50.00 +Total SLOC: 12 +""" + self.assertEqual(expected, output.getvalue()) + + +if __name__ == "__main__": + unittest.main()