Skip to content
This repository has been archived by the owner on Apr 6, 2022. It is now read-only.

Commit

Permalink
[FIXED JENKINS-32295] Reduce priorities of parser.
Browse files Browse the repository at this point in the history
  • Loading branch information
uhafner committed May 31, 2016
1 parent 737a300 commit 77c4b4d
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 18 deletions.
5 changes: 1 addition & 4 deletions src/main/java/hudson/plugins/warnings/parser/Pep8Parser.java
Expand Up @@ -43,10 +43,7 @@ protected boolean isLineInteresting(final String line) {
}

private Priority mapPriority(final String priority) {
if (priority.contains("F") || priority.contains("E") || priority.contains("W")) {
return Priority.HIGH;
}
else if (priority.contains("R")) {
if (priority.contains("E")) {
return Priority.NORMAL;
}
else {
Expand Down
39 changes: 29 additions & 10 deletions src/test/java/hudson/plugins/warnings/parser/Pep8ParserTest.java
Expand Up @@ -5,6 +5,9 @@
import java.util.Iterator;

import org.junit.Test;
import org.jvnet.hudson.test.Issue;

import static org.junit.Assert.assertEquals;

import hudson.plugins.analysis.util.model.FileAnnotation;
import hudson.plugins.analysis.util.model.Priority;
Expand All @@ -18,36 +21,52 @@ public class Pep8ParserTest extends ParserTester {
private static final String WARNING_TYPE = "Pep8";

/**
* Parses a file with a simple and a complex warning and 2 complex warnings with lower Priority.
* Parses a file with W and E warnings.
*
* @throws IOException
* if the file could not be read
*/
@Test
@Test @Issue("32295")
public void testParseSimpleAndComplexMessage() throws IOException {
Pep8Parser parser = new Pep8Parser();

Collection<FileAnnotation> warnings = parser.parse(openFile());

assertEquals("Wrong number of warnings detected.", 8, warnings.size());

Iterator<FileAnnotation> iterator = warnings.iterator();
FileAnnotation warning = iterator.next();

checkWarning(warning, 1, 2, "trailing whitespace", "trunk/src/python/file.py",
WARNING_TYPE, "W291", Priority.HIGH);
checkWarning(warning, 69, 11, "multiple imports on one line", "optparse.py",
WARNING_TYPE, "E401", Priority.NORMAL);
warning = iterator.next();

checkWarning(warning, 77, 1, "expected 2 blank lines, found 1", "optparse.py",
WARNING_TYPE, "E302", Priority.NORMAL);
warning = iterator.next();

checkWarning(warning, 88, 5, "expected 1 blank line, found 0", "optparse.py",
WARNING_TYPE, "E301", Priority.NORMAL);
warning = iterator.next();

checkWarning(warning, 98, 11, "Message #has! 12special-_ chars|?.",
"trunk/src/python/file.py", WARNING_TYPE, "E111", Priority.HIGH);
checkWarning(warning, 222, 34, "deprecated form of raising exception", "optparse.py",
WARNING_TYPE, "W602", Priority.LOW);
warning = iterator.next();

checkWarning(warning, 347, 31, "whitespace before '('", "optparse.py",
WARNING_TYPE, "E211", Priority.NORMAL);
warning = iterator.next();

checkWarning(warning, 98, 11, "Message #has! 12special-_ chars|?.",
"trunk2/src/python/file.py", WARNING_TYPE, "R111", Priority.NORMAL);
checkWarning(warning, 357, 17, "whitespace after '{'", "optparse.py",
WARNING_TYPE, "E201", Priority.NORMAL);
warning = iterator.next();

checkWarning(warning, 472, 29, "multiple spaces before operator", "optparse.py",
WARNING_TYPE, "E221", Priority.NORMAL);
warning = iterator.next();

checkWarning(warning, 98, 11, "Message #has! 12special-_ chars|?.",
"trunk3/src/python/file.py", WARNING_TYPE, "C111", Priority.LOW);
checkWarning(warning, 544, 21, ".has_key() is deprecated, use 'in'", "optparse.py",
WARNING_TYPE, "W601", Priority.LOW);
}

@Override
Expand Down
12 changes: 8 additions & 4 deletions src/test/resources/hudson/plugins/warnings/parser/pep8Test.txt
@@ -1,4 +1,8 @@
trunk/src/python/file.py:1:2: W291 trailing whitespace
trunk/src/python/file.py:98:11: E111 Message #has! 12special-_ chars|?.
trunk2/src/python/file.py:98:11: R111 Message #has! 12special-_ chars|?.
trunk3/src/python/file.py:98:11: C111 Message #has! 12special-_ chars|?.
optparse.py:69:11: E401 multiple imports on one line
optparse.py:77:1: E302 expected 2 blank lines, found 1
optparse.py:88:5: E301 expected 1 blank line, found 0
optparse.py:222:34: W602 deprecated form of raising exception
optparse.py:347:31: E211 whitespace before '('
optparse.py:357:17: E201 whitespace after '{'
optparse.py:472:29: E221 multiple spaces before operator
optparse.py:544:21: W601 .has_key() is deprecated, use 'in'

0 comments on commit 77c4b4d

Please sign in to comment.