-
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
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
73ff6af
initial commit
xb058t 3ec795f
pylint fixes
xb058t 7787aa9
requested changes applied
xb058t 9d63a86
Merge remote-tracking branch 'upstream/master' into cmd-runs
xb058t 27704e2
Applied requested change
xb058t 1d6697f
Added tests
xb058t 25bb553
Added requested changes, removed --details and --enabled-checkers flags
xb058t 0936c70
Remove --details tests
xb058t 28bb6a9
Fixed tests
xb058t d24cb1d
Linter fixes
xb058t 5998c90
Tests and lintern fixes
xb058t 4c1b942
Added requested changes
xb058t File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| import io | ||
| 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"]) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -230,23 +230,18 @@ 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 |
||
| self.assertIn( | ||
| 'core.NullDereference', | ||
| data['analyzerStatistics']['clangsa']['enabledCheckers']) | ||
|
|
||
| def test_proxy_settings(self): | ||
| """ Test proxy settings validation. """ | ||
|
|
@@ -352,8 +347,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) | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 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.