-
Notifications
You must be signed in to change notification settings - Fork 458
List enabled checkers in CLI: CodeChecker cmd runs #4468
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 11 commits
73ff6af
3ec795f
7787aa9
9d63a86
27704e2
1d6697f
25bb553
0936c70
28bb6a9
d24cb1d
5998c90
4c1b942
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| import io | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This unit test does not test the database query. So please add a function test too in https://github.com/Ericsson/codechecker/blob/master/web/tests/functional/cmdline/test_cmdline.py where the other function tests of CodeChecker cmd runs is tested. |
||
| import json | ||
| import unittest | ||
| from types import SimpleNamespace | ||
| from contextlib import redirect_stdout | ||
| from unittest.mock import Mock, patch | ||
|
|
||
| from codechecker_client import cmd_line_client | ||
|
|
||
|
|
||
| class Args(SimpleNamespace): | ||
| def __contains__(self, key): | ||
| return hasattr(self, key) | ||
|
|
||
|
|
||
| class DummyRun: | ||
| def __init__(self, runId, name="r"): | ||
| self.runId = runId | ||
| self.name = name | ||
| self.resultCount = 0 | ||
| self.analyzerStatistics = {} | ||
| self.runDate = "" | ||
| self.versionTag = "" | ||
| self.duration = 0 | ||
| self.description = "" | ||
| self.codeCheckerVersion = "" | ||
|
|
||
|
|
||
| class DummyCheckerCfg: | ||
| def __init__(self, enabled): | ||
| self.enabled = enabled | ||
|
|
||
|
|
||
| def make_analysis_info(checkers_dict): | ||
| checkers = {} | ||
| for analyzer, ckrs in checkers_dict.items(): | ||
| checkers[analyzer] = {name: DummyCheckerCfg(en) for name, en in ckrs.items()} | ||
| return SimpleNamespace(checkers=checkers) | ||
|
|
||
|
|
||
| class ListRunsEnabledCheckersTest(unittest.TestCase): | ||
| def setUp(self): | ||
| cmd_line_client.LOG = SimpleNamespace(error=Mock(), warning=Mock(), info=Mock()) | ||
|
|
||
| @patch("codechecker_client.cmd_line_client.init_logger") | ||
| @patch("codechecker_client.cmd_line_client.setup_client") | ||
| @patch("codechecker_client.cmd_line_client.get_run_data") | ||
| def test_enabled_checkers_json(self, get_run_data, setup_client, init_logger): | ||
| client = Mock() | ||
| setup_client.return_value = client | ||
| get_run_data.return_value = [DummyRun(1)] | ||
|
|
||
| client.getAnalysisInfo.return_value = [ | ||
| make_analysis_info({"clangsa": {"a": True}}) | ||
| ] | ||
| client.getAnalysisStatistics.return_value = { | ||
| "clangsa": SimpleNamespace( | ||
| version="1", | ||
| failed=0, | ||
| successful=1, | ||
| failedFilePaths=[], | ||
| ) | ||
| } | ||
|
|
||
| args = Args( | ||
| product_url="dummy", | ||
| sort_type="name", | ||
| sort_order="asc", | ||
| output_format="json" | ||
| ) | ||
|
|
||
| buf = io.StringIO() | ||
| with redirect_stdout(buf): | ||
| cmd_line_client.handle_list_runs(args) | ||
|
|
||
| data = json.loads(buf.getvalue()) | ||
| self.assertEqual(len(data), 1) | ||
| run_entry = data[0] | ||
| self.assertEqual(len(run_entry), 1) | ||
| _, run_data = next(iter(run_entry.items())) | ||
| self.assertIn("analyzerStatistics", run_data) | ||
| self.assertIn("clangsa", run_data["analyzerStatistics"]) | ||
| stats = run_data["analyzerStatistics"]["clangsa"] | ||
| self.assertIn("enabledCheckers", stats) | ||
| self.assertEqual(stats["enabledCheckers"], ["a"]) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -230,23 +230,15 @@ def test_runs_analysis_statistics(self): | |
| '-o', 'json', '--url', str(self.server_url)] | ||
| ret, res, _ = run_cmd(res_cmd, environ=environ) | ||
|
|
||
| self.assertEqual(0, ret) | ||
| for run in json.loads(res): | ||
| for data in run.values(): | ||
| self.assertIsNone( | ||
| data['analyzerStatistics']['clangsa']['failedFilePaths']) | ||
|
|
||
| res_cmd = [self._codechecker_cmd, 'cmd', 'runs', | ||
| '-o', 'json', '--url', str(self.server_url), | ||
| '--details'] | ||
| ret, res, _ = run_cmd(res_cmd, environ=environ) | ||
|
|
||
| self.assertEqual(0, ret) | ||
| for run in json.loads(res): | ||
| for data in run.values(): | ||
| self.assertEqual( | ||
| data['analyzerStatistics']['clangsa']['failedFilePaths'], | ||
| []) | ||
| self.assertNotEqual( | ||
| data['analyzerStatistics']['clangsa']['enabledCheckers'], | ||
| []) | ||
|
Comment on lines
+239
to
+241
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should check if the list contains a specific checker that is known to be enabled. The problem with this check is that this assertion is true if the value is |
||
|
|
||
| def test_proxy_settings(self): | ||
| """ Test proxy settings validation. """ | ||
|
|
@@ -352,8 +344,7 @@ def test_detailed_results_contain_run_names(self): | |
| check_env = self._test_config['codechecker_cfg']['check_env'] | ||
|
|
||
| res_cmd = [self._codechecker_cmd, 'cmd', 'results', 'test_files1*', | ||
| 'test_files1*', '-o', 'json', '--url', str(self.server_url), | ||
| '--details'] | ||
| 'test_files1*', '-o', 'json', '--url', str(self.server_url)] | ||
|
|
||
| ret, out, _ = run_cmd(res_cmd, environ=check_env) | ||
| self.assertEqual(0, ret) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would print the output indented.