# pylint: disable=missing-function-docstring,line-too-long
import unittest
+import io
+import sys
from collections import OrderedDict
import json
from .engine import KconfigCheck, CmdlineCheck, VersionCheck, OR, AND, populate_with_data, perform_checks
kernel_version = (42, 43)
# 5. run the engine
- result = []
- self.run_engine(config_checklist,
- parsed_kconfig_options, parsed_cmdline_options, kernel_version,
- result)
+ self.run_engine(config_checklist, parsed_kconfig_options, parsed_cmdline_options, kernel_version)
# 6. check that the results are correct
- # self.assertEqual(...
+ result = []
+ self.get_engine_result(config_checklist, result, 'json')
+ self.assertEqual(...
"""
@staticmethod
- def run_engine(checklist,
- parsed_kconfig_options, parsed_cmdline_options, kernel_version,
- result):
+ def run_engine(checklist, parsed_kconfig_options, parsed_cmdline_options, kernel_version):
# populate the checklist with data
if parsed_kconfig_options:
populate_with_data(checklist, parsed_kconfig_options, 'kconfig')
# print the table with the results
print('TABLE:')
for opt in checklist:
- opt.table_print(None, True) # default mode, with_results
+ opt.table_print('verbose', True) # verbose mode, with_results
print()
+ print('=' * 121)
# print the results in JSON
print('JSON:')
+ result = []
for opt in checklist:
result.append(opt.json_dump(True)) # with_results
print(json.dumps(result))
print()
+ @staticmethod
+ def get_engine_result(checklist, result, result_type):
+ assert(result_type in ('json', 'stdout')), \
+ f'invalid result type "{result_type}"'
+
+ if result_type == 'json':
+ for opt in checklist:
+ result.append(opt.json_dump(True)) # with_results
+ return
+
+ captured_output = io.StringIO()
+ stdout_backup = sys.stdout
+ sys.stdout = captured_output
+ for opt in checklist:
+ opt.table_print('verbose', True) # verbose mode, with_results
+ sys.stdout = stdout_backup
+ result.append(captured_output.getvalue())
+
def test_single_kconfig(self):
# 1. prepare the checklist
config_checklist = []
parsed_kconfig_options['CONFIG_NAME_9'] = '0'
# 3. run the engine
- result = []
- self.run_engine(config_checklist, parsed_kconfig_options, None, None, result)
+ self.run_engine(config_checklist, parsed_kconfig_options, None, None)
# 4. check that the results are correct
+ result = []
+ self.get_engine_result(config_checklist, result, 'json')
self.assertEqual(
result,
[["CONFIG_NAME_1", "kconfig", "expected_1", "decision_1", "reason_1", "OK"],
parsed_cmdline_options['name_9'] = '0'
# 3. run the engine
- result = []
- self.run_engine(config_checklist, None, parsed_cmdline_options, None, result)
+ self.run_engine(config_checklist, None, parsed_cmdline_options, None)
# 4. check that the results are correct
+ result = []
+ self.get_engine_result(config_checklist, result, 'json')
self.assertEqual(
result,
[["name_1", "cmdline", "expected_1", "decision_1", "reason_1", "OK"],
parsed_kconfig_options['CONFIG_NAME_11'] = 'really_not_off'
# 3. run the engine
- result = []
- self.run_engine(config_checklist, parsed_kconfig_options, None, None, result)
+ self.run_engine(config_checklist, parsed_kconfig_options, None, None)
# 4. check that the results are correct
+ result = []
+ self.get_engine_result(config_checklist, result, 'json')
self.assertEqual(
result,
[["CONFIG_NAME_1", "kconfig", "expected_1", "decision_1", "reason_1", "OK"],
parsed_kconfig_options['CONFIG_NAME_12'] = 'expected_12'
# 3. run the engine
- result = []
- self.run_engine(config_checklist, parsed_kconfig_options, None, None, result)
+ self.run_engine(config_checklist, parsed_kconfig_options, None, None)
# 4. check that the results are correct
+ result = []
+ self.get_engine_result(config_checklist, result, 'json')
self.assertEqual(
result,
[["CONFIG_NAME_1", "kconfig", "expected_1", "decision_1", "reason_1", "OK"],
kernel_version = (42, 43)
# 4. run the engine
- result = []
- self.run_engine(config_checklist, parsed_kconfig_options, None, kernel_version, result)
+ self.run_engine(config_checklist, parsed_kconfig_options, None, kernel_version)
# 5. check that the results are correct
+ result = []
+ self.get_engine_result(config_checklist, result, 'json')
self.assertEqual(
result,
[["CONFIG_NAME_1", "kconfig", "expected_1", "decision_1", "reason_1", "OK: version >= 41.101"],