|
26 | 26 | from pysonar_scanner.configuration.properties import ( |
27 | 27 | SONAR_HOST_URL, |
28 | 28 | SONAR_ORGANIZATION, |
| 29 | + SONAR_PYTHON_ANALYSIS_PARALLEL, |
| 30 | + SONAR_PYTHON_ANALYSIS_THREADS, |
29 | 31 | SONAR_PYTHON_BANDIT_REPORT_PATHS, |
30 | 32 | SONAR_PYTHON_FLAKE8_REPORT_PATHS, |
31 | 33 | SONAR_PYTHON_MYPY_REPORT_PATHS, |
|
159 | 161 | SONAR_PYTHON_COVERAGE_REPORT_PATHS: "path/to/coverage1,path/to/coverage2", |
160 | 162 | SONAR_COVERAGE_EXCLUSIONS: "*/.local/*,/usr/*,utils/tirefire.py", |
161 | 163 | SONAR_PYTHON_SKIP_UNCHANGED: True, |
| 164 | + SONAR_PYTHON_ANALYSIS_PARALLEL: True, |
| 165 | + SONAR_PYTHON_ANALYSIS_THREADS: 2, |
162 | 166 | SONAR_PYTHON_XUNIT_REPORT_PATH: "path/to/xunit/report", |
163 | 167 | SONAR_PYTHON_XUNIT_SKIP_DETAILS: True, |
164 | 168 | SONAR_PYTHON_MYPY_REPORT_PATHS: "path/to/mypy/reports", |
@@ -207,6 +211,36 @@ def test_alternative_cli_args(self): |
207 | 211 | } |
208 | 212 | self.assertDictEqual(configuration, expected_configuration) |
209 | 213 |
|
| 214 | + def test_alternative_analysis_threads_cli_args(self): |
| 215 | + base_args = ["myscript.py", "-t", "myToken", "--sonar-project-key", "myProjectKey"] |
| 216 | + report_args = ["--nr-analysis-threads", "3"] |
| 217 | + |
| 218 | + expected_configuration = { |
| 219 | + SONAR_TOKEN: "myToken", |
| 220 | + SONAR_PROJECT_KEY: "myProjectKey", |
| 221 | + SONAR_PYTHON_ANALYSIS_THREADS: 3, |
| 222 | + } |
| 223 | + |
| 224 | + with patch("sys.argv", base_args + report_args), patch("sys.stderr", new=StringIO()): |
| 225 | + configuration = CliConfigurationLoader.load() |
| 226 | + self.assertDictEqual(configuration, expected_configuration) |
| 227 | + |
| 228 | + def test_alternative_analysis_single_threaded_cli_args(self): |
| 229 | + base_args = ["myscript.py", "-t", "myToken", "--sonar-project-key", "myProjectKey"] |
| 230 | + report_args = [ |
| 231 | + "--no-analysis-in-parallel", |
| 232 | + ] |
| 233 | + |
| 234 | + expected_configuration = { |
| 235 | + SONAR_TOKEN: "myToken", |
| 236 | + SONAR_PROJECT_KEY: "myProjectKey", |
| 237 | + SONAR_PYTHON_ANALYSIS_PARALLEL: False, |
| 238 | + } |
| 239 | + |
| 240 | + with patch("sys.argv", base_args + report_args), patch("sys.stderr", new=StringIO()): |
| 241 | + configuration = CliConfigurationLoader.load() |
| 242 | + self.assertDictEqual(configuration, expected_configuration) |
| 243 | + |
210 | 244 | def test_alternative_report_cli_args(self): |
211 | 245 | base_args = ["myscript.py", "-t", "myToken", "--sonar-project-key", "myProjectKey"] |
212 | 246 | report_args = [ |
@@ -404,6 +438,9 @@ def test_impossible_os_choice(self): |
404 | 438 | "module1,module2", |
405 | 439 | "--sonar-scanner-java-heap-size", |
406 | 440 | "8000Mb", |
| 441 | + "--analysis-in-parallel", |
| 442 | + "--nr-analysis-threads", |
| 443 | + "2", |
407 | 444 | ], |
408 | 445 | ) |
409 | 446 | def test_all_cli_args(self): |
@@ -474,6 +511,8 @@ def test_all_cli_args(self): |
474 | 511 | "-Dsonar.python.pylint.reportPath=path/to/pylint/report", |
475 | 512 | "-Dsonar.python.coverage.reportPaths=path/to/coverage1,path/to/coverage2", |
476 | 513 | "-Dsonar.coverage.exclusions=*/.local/*,/usr/*,utils/tirefire.py", |
| 514 | + "-Dsonar.python.analysis.parallel", |
| 515 | + "-Dsonar.python.analysis.threads=2", |
477 | 516 | "-Dsonar.python.skipUnchanged=true", |
478 | 517 | "-Dsonar.python.xunit.reportPath=path/to/xunit/report", |
479 | 518 | "-Dsonar.python.xunit.skipDetails=true", |
|
0 commit comments