|
17 | 17 | */ |
18 | 18 | package org.greencodeinitiative.creedengo.python.integration.tests; |
19 | 19 |
|
20 | | -import org.junit.jupiter.api.Test; |
21 | | -import org.sonarqube.ws.Issues; |
22 | | -import org.sonarqube.ws.Measures; |
| 20 | +import static java.util.Optional.ofNullable; |
| 21 | +import static org.assertj.core.api.Assertions.assertThat; |
23 | 22 |
|
24 | 23 | import java.util.List; |
25 | 24 | import java.util.Map; |
26 | 25 |
|
27 | | -import static java.util.Optional.ofNullable; |
28 | | -import static org.assertj.core.api.Assertions.assertThat; |
| 26 | +import org.junit.jupiter.api.Test; |
| 27 | +import org.sonarqube.ws.Issues; |
| 28 | +import org.sonarqube.ws.Measures; |
29 | 29 |
|
30 | 30 | class GCIRulesIT extends GCIRulesBase { |
31 | 31 |
|
@@ -273,4 +273,145 @@ void testGCI203_compliant() { |
273 | 273 |
|
274 | 274 | } |
275 | 275 |
|
| 276 | + @Test |
| 277 | + void testGCI96() { |
| 278 | + String filePath = "src/pandasRequireUsecols.py"; |
| 279 | + String ruleId = "creedengo-python:GCI96"; |
| 280 | + String ruleMsg = "Specify 'usecols' or 'columns' when reading a DataFrame using Pandas to load only necessary columns"; |
| 281 | + int[] startLines = new int[]{ |
| 282 | + 3, 4, 5, 6, 7, 16, 19 |
| 283 | + }; |
| 284 | + int[] endLines = new int[]{ |
| 285 | + 3, 4, 5, 6, 7, 16, 19 |
| 286 | + }; |
| 287 | + |
| 288 | + checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines, SEVERITY, TYPE, EFFORT_10MIN); |
| 289 | + } |
| 290 | + |
| 291 | + @Test |
| 292 | + void testGCI97(){ |
| 293 | + String filePath = "src/optimizeSquareComputation.py"; |
| 294 | + String ruleId = "creedengo-python:GCI97"; |
| 295 | + String ruleMsg = "Use x*x instead of x**2 or math.pow(x,2) to calculate the square of a value"; |
| 296 | + int[] startLines = new int[]{ |
| 297 | + 4, 7, 19, 20, 25, 26, 31, 38 |
| 298 | + }; |
| 299 | + int[] endLines = new int[]{ |
| 300 | + 4, 7, 19, 20, 25, 26, 31, 38 |
| 301 | + }; |
| 302 | + |
| 303 | + checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines, SEVERITY, TYPE, EFFORT_1MIN); |
| 304 | + } |
| 305 | + |
| 306 | + @Test |
| 307 | + void testGCI99(){ |
| 308 | + String filePath = "src/avoidCSVFormat.py"; |
| 309 | + String ruleId = "creedengo-python:GCI99"; |
| 310 | + String ruleMsg = "Use Parquet or Feather format instead of CSV"; |
| 311 | + int[] startLines = new int[]{ |
| 312 | + // FIXME DDC : check why line 17 is not detected TI but detected in UT !!! |
| 313 | +// 4, 6, 10, 12, 14, 15, 17, 18, 23, 39, 47, 48 |
| 314 | + 4, 6, 10, 12, 14, 15, 18, 23, 39, 47, 48 |
| 315 | + }; |
| 316 | + int[] endLines = new int[]{ |
| 317 | +// 4, 6, 10, 12, 14, 15, 17, 18, 23, 39, 47, 48 |
| 318 | + 4, 6, 10, 12, 14, 15, 18, 23, 39, 47, 48 |
| 319 | + }; |
| 320 | + |
| 321 | + checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines, SEVERITY, TYPE, EFFORT_50MIN); |
| 322 | + } |
| 323 | + |
| 324 | + @Test |
| 325 | + void testGCI101(){ |
| 326 | + String filePath = "src/avoidConvBiasBeforeBatchNorm.py"; |
| 327 | + String ruleId = "creedengo-python:GCI101"; |
| 328 | + String ruleMsg = "Remove bias for convolutions before batch norm layers to save time and memory."; |
| 329 | + int[] startLines = new int[]{ |
| 330 | + 49, 71, 115, 136, 156, 178 |
| 331 | + }; |
| 332 | + int[] endLines = new int[]{ |
| 333 | + 49, 71, 115, 136, 156, 178 |
| 334 | + }; |
| 335 | + |
| 336 | + checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines, SEVERITY, TYPE, EFFORT_10MIN); |
| 337 | + } |
| 338 | + |
| 339 | + @Test |
| 340 | + void testGCI102(){ |
| 341 | + String filePath = "src/avoidNonPinnedMemoryForDataloaders.py"; |
| 342 | + String ruleId = "creedengo-python:GCI102"; |
| 343 | + String ruleMsg = "Use pinned memory to reduce data transfer in RAM."; |
| 344 | + int[] startLines = new int[]{ |
| 345 | + 7, 8, 9, 10, 11, 12, 13, 14 |
| 346 | + }; |
| 347 | + int[] endLines = new int[]{ |
| 348 | + 7, 8, 9, 10, 11, 12, 13, 14 |
| 349 | + }; |
| 350 | + |
| 351 | + checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines, SEVERITY, TYPE, EFFORT_10MIN); |
| 352 | + } |
| 353 | + |
| 354 | + @Test |
| 355 | + void testGCI103(){ |
| 356 | + |
| 357 | + String filePath = "src/dictionaryItemsUnused.py"; |
| 358 | + String ruleId = "creedengo-python:GCI103"; |
| 359 | + String ruleMsg = "Use dict.keys() or dict.values() instead of dict.items() when only one part of the key-value pair is used"; |
| 360 | + int[] startLines = new int[]{ |
| 361 | + 5, 8, 24, 27, 36 |
| 362 | + }; |
| 363 | + int[] endLines = new int[]{ |
| 364 | + 5, 8, 24, 27, 36 |
| 365 | + }; |
| 366 | + |
| 367 | + checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines, SEVERITY, TYPE, EFFORT_1MIN); |
| 368 | + } |
| 369 | + |
| 370 | + @Test |
| 371 | + void testGCI105() { |
| 372 | + |
| 373 | + String filePath = "src/stringConcatenation.py"; |
| 374 | + String ruleId = "creedengo-python:GCI105"; |
| 375 | + String ruleMsg = "Concatenation of strings should be done using f-strings or str.join()"; |
| 376 | + int[] startLines = new int[]{ |
| 377 | + 5, 8, 10, 32, 38 |
| 378 | + }; |
| 379 | + int[] endLines = new int[]{ |
| 380 | + 5, 8, 10, 32, 38 |
| 381 | + }; |
| 382 | + |
| 383 | + checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines, SEVERITY, TYPE, EFFORT_1MIN); |
| 384 | + } |
| 385 | + |
| 386 | + @Test |
| 387 | + void testGCI106() { |
| 388 | + String filePath = "src/avoidSqrtInLoop.py"; |
| 389 | + String ruleId = "creedengo-python:GCI106"; |
| 390 | + String ruleMsg = "Avoid using scalar sqrt functions in loops. Apply vectorized sqrt operations on arrays directly."; |
| 391 | + int[] startLines = new int[]{ |
| 392 | + 7, 11, 16, 21, 45, 52, 60 |
| 393 | + }; |
| 394 | + int[] endLines = new int[]{ |
| 395 | + 7, 11, 16, 21, 45, 52, 60 |
| 396 | + }; |
| 397 | + checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines, SEVERITY, TYPE, EFFORT_5MIN); |
| 398 | + |
| 399 | + } |
| 400 | + |
| 401 | + @Test |
| 402 | + void testGCI107(){ |
| 403 | + |
| 404 | + String filePath = "src/avoidIterativeMatrixOperations.py"; |
| 405 | + String ruleId = "creedengo-python:GCI107"; |
| 406 | + String ruleMsg = "Avoid iterative matrix operations, use numpy dot or outer function instead"; |
| 407 | + int[] startLines = new int[]{ |
| 408 | + 8, 20, 36, 46, 75, 83, 91, 106, 115 |
| 409 | + }; |
| 410 | + int[] endLines = new int[]{ |
| 411 | + 8, 20, 36, 46, 75, 83, 91, 106, 115 |
| 412 | + }; |
| 413 | + |
| 414 | + checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines, SEVERITY, TYPE, EFFORT_10MIN); |
| 415 | + } |
| 416 | + |
276 | 417 | } |
0 commit comments