Skip to content

Commit e3d7c1e

Browse files
committed
[PLUTO-1411] Add pylint test
1 parent 90d3e58 commit e3d7c1e

File tree

4 files changed

+201
-0
lines changed

4 files changed

+201
-0
lines changed

.github/workflows/it-test.yml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
name: Pylint plugin test
2+
3+
permissions:
4+
contents: write
5+
6+
on:
7+
push:
8+
paths:
9+
- 'plugins/tools/pylint/**'
10+
11+
12+
jobs:
13+
test:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- name: Checkout code
17+
uses: actions/checkout@v4
18+
19+
- name: Set up Go
20+
uses: actions/setup-go@v5
21+
with:
22+
go-version: '1.21'
23+
cache: true
24+
25+
- name: Build CLI
26+
run: |
27+
go build -o cli-v2 ./cli-v2.go
28+
chmod +x cli-v2
29+
30+
- name: Run Pylint plugin tests
31+
run: |
32+
# Store the path to the CLI
33+
CLI_PATH="$(pwd)/cli-v2"
34+
# Change to test directory
35+
cd plugins/tools/pylint/test/src
36+
# Install the plugin
37+
"$CLI_PATH" install
38+
# Run analysis
39+
"$CLI_PATH" analyze --tool pylint --format sarif --output actual.sarif
40+
# Convert absolute paths to relative paths in the output
41+
sed -i 's|file:///home/runner/work/codacy-cli-v2/codacy-cli-v2/|file:///|g' actual.sarif
42+
# Compare with expected output
43+
jq --sort-keys . expected.sarif > expected.sorted.json
44+
jq --sort-keys . actual.sarif > actual.sorted.json
45+
diff expected.sorted.json actual.sorted.json
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
runtimes:
2+
3+
tools:
4+
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
{
2+
3+
"$schema": "https://raw.githubusercontent.com/oasis-tcs/sarif-spec/master/Schemata/sarif-schema-2.1.0.json",
4+
"version": "2.1.0",
5+
"runs": [
6+
{
7+
"tool": {
8+
"driver": {
9+
"name": "Pylint",
10+
"version": "3.3.6",
11+
"informationUri": "https://pylint.org",
12+
"rules": null
13+
}
14+
},
15+
"results": [
16+
{
17+
"ruleId": "missing-final-newline",
18+
"level": "note",
19+
"message": {
20+
"text": "Final newline missing"
21+
},
22+
"locations": [
23+
{
24+
"physicalLocation": {
25+
"artifactLocation": {
26+
"uri": "test_file.py"
27+
},
28+
"region": {
29+
"startLine": 33,
30+
"startColumn": 0
31+
}
32+
}
33+
}
34+
]
35+
},
36+
{
37+
"ruleId": "too-many-arguments",
38+
"level": "note",
39+
"message": {
40+
"text": "Too many arguments (11/5)"
41+
},
42+
"locations": [
43+
{
44+
"physicalLocation": {
45+
"artifactLocation": {
46+
"uri": "test_file.py"
47+
},
48+
"region": {
49+
"startLine": 16,
50+
"startColumn": 0
51+
}
52+
}
53+
}
54+
]
55+
},
56+
{
57+
"ruleId": "too-many-positional-arguments",
58+
"level": "note",
59+
"message": {
60+
"text": "Too many positional arguments (11/5)"
61+
},
62+
"locations": [
63+
{
64+
"physicalLocation": {
65+
"artifactLocation": {
66+
"uri": "test_file.py"
67+
},
68+
"region": {
69+
"startLine": 16,
70+
"startColumn": 0
71+
}
72+
}
73+
}
74+
]
75+
},
76+
{
77+
"ruleId": "unused-import",
78+
"level": "warning",
79+
"message": {
80+
"text": "Unused import os"
81+
},
82+
"locations": [
83+
{
84+
"physicalLocation": {
85+
"artifactLocation": {
86+
"uri": "test_file.py"
87+
},
88+
"region": {
89+
"startLine": 8,
90+
"startColumn": 0
91+
}
92+
}
93+
}
94+
]
95+
},
96+
{
97+
"ruleId": "unused-import",
98+
"level": "warning",
99+
"message": {
100+
"text": "Unused import sys"
101+
},
102+
"locations": [
103+
{
104+
"physicalLocation": {
105+
"artifactLocation": {
106+
"uri": "test_file.py"
107+
},
108+
"region": {
109+
"startLine": 9,
110+
"startColumn": 0
111+
}
112+
}
113+
}
114+
]
115+
}
116+
]
117+
}
118+
]
119+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/usr/bin/env python3
2+
# -*- coding: utf-8 -*-
3+
4+
"""
5+
Test file for pylint analysis
6+
"""
7+
8+
import os
9+
import sys
10+
11+
def unused_variable():
12+
"""Function with unused variable"""
13+
x = 10 # pylint: disable=unused-variable
14+
return True
15+
16+
def too_many_arguments(a, b, c, d, e, f, g, h, i, j, k):
17+
"""Function with too many arguments"""
18+
return a + b + c + d + e + f + g + h + i + j + k
19+
20+
def undefined_variable():
21+
"""Function with undefined variable"""
22+
print(undefined_var) # pylint: disable=undefined-variable
23+
24+
def bad_variable_name():
25+
"""Function with bad variable name"""
26+
A = 1 # pylint: disable=invalid-name
27+
return A
28+
29+
if __name__ == "__main__":
30+
unused_variable()
31+
too_many_arguments(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11)
32+
undefined_variable()
33+
bad_variable_name()

0 commit comments

Comments
 (0)