Use trim() to remove trailing whitespace before using values from csv#45
Use trim() to remove trailing whitespace before using values from csv#45skelliam wants to merge 1 commit into
Conversation
Use trim() on label values Update test cases and test more than one csv file Add test case that excludes only the last row
| // first create a FilePath to load the test Properties file. | ||
| File workspaceDirFile = new File("target/test-classes/"); | ||
| FilePath workspaceRootDir = new FilePath(workspaceDirFile); | ||
| for (int testfilenum = 0; testfilenum < FILES.length; testfilenum++) { |
There was a problem hiding this comment.
Here I wrapped the test case with a for loop to test more than one csv file.
| CSVSeries series = new CSVSeries(FILES[0], null, null, null, true); | ||
| assertTrue(series.getDisplayTableFlag()); | ||
| CSVSeries series; | ||
| for (int testfilenum = 0; testfilenum < FILES.length; testfilenum++) { |
There was a problem hiding this comment.
again wrap existing test case with for loop to test multiple files
| // first create a FilePath to load the test Properties file. | ||
| File workspaceDirFile = new File("target/test-classes/"); | ||
| FilePath workspaceRootDir = new FilePath(workspaceDirFile); | ||
| for (int testfilenum = 0; testfilenum < FILES.length; testfilenum++) { |
There was a problem hiding this comment.
test multiple files again
|
|
||
| // Create a new CSV series. | ||
| CSVSeries series = new CSVSeries(FILES[0], "http://localhost:8080/%name%/%index%/", "OFF", "", false); | ||
| public void testCSVSeriesIncludeOnlyLastColumn() { |
There was a problem hiding this comment.
new test case, include only the last column by name
| @@ -0,0 +1,3 @@ | |||
| foo,bar,thing | |||
| 07.81,7,81 | |||
| 25.42,7,42 No newline at end of file | |||
There was a problem hiding this comment.
CSV file from Windows echo -- there is an extra space (0x20) character at the end of each line that messes up the plot plugin.
There was a problem hiding this comment.
It doesn't break plotting for me on Mac OS (don't have a Windows machine to check), and plots constructing for me even without this change.
Thanks for adding tests, those are really helpful.
Few tweaks are still required. Other than that everything is great.
| ++lineNum; | ||
| } | ||
| } catch (IOException e) { | ||
| assertTrue("Line count is not equal " + lineNum + " expected " + LINES[testfilenum], LINES[testfilenum] == lineNum); |
There was a problem hiding this comment.
For some reason, Checkstyle line length rule isn't enforced in tests. I need to fix that.
There was a problem hiding this comment.
But if you can reformat the code according to max line length = 100 rule, that would be awesome.
There was a problem hiding this comment.
@vgaidarji For testing on MacOS, you only need to make sure that a trailing space is added at the end of the last label and the last value in each row. "echo" in MacOS or Linux probably does not have the same effect. The other thing you could do is remove the trim() statements I added in the functional code, but keep the tests the same. Then run the tests and see if they fail on MacOS.
There was a problem hiding this comment.
@skelliam Yes, I did exactly that and it works for me even before trim() was added.
I have added spaces after the last label and after each last value in each line, and then selected that label in plot configuration and specified it without trailing space. Plots rendered just fine.
There was a problem hiding this comment.
@vgaidarji, maybe it has something to do with the CR LF endings in Windows? If you don't implement trim(), do the new tests pass? If so that is really strange...
There was a problem hiding this comment.
I would really like to somehow have another user verify this -- I guess it is pretty low risk though.
There was a problem hiding this comment.
@skelliam yes, it's a very low risk. Trimming trailing spaces sounds very reasonable to me.
I've verified following cases:
- plot plugin build from 1ccbcc8
- "column" & "value" &
include column by name"column" = plots are shown - "column " & "value " &
include column by name"column" = plots are shown - "column " & "value " &
include column by name"column " = plots are not shown - "column" & "value" &
include column by name"column " = plots are not shown
- Plot plugin 2.0.3 version
- "column" & "value" &
include column by name"column" = plots are shown - "column " & "value " &
include column by name"column" = plots are shown - "column " & "value " &
include column by name"column " = plots are not shown - "column" & "value" &
include column by name"column " = plots are not shown
As you can see, the behavior is the same. I'm on Mac OS High Sierra 10.13.3.
I'm just wondering why I can't reproduce the issue you described and if it's OS related:
If someone wants to reproduce this on Windows, I used this as a Windows batch
set plotfile=test.csv
IF NOT EXIST %plotfile% (
echo foo,bar,thing > %plotfile%
)
echo %time:~-5%,7,%time:~-2% >> %plotfile%
Now try to plot only the last column named "thing" using the plot plugin. It will not get plotted because the plugin only discovers the name "thing " (with space).
As I'm not getting plots when column name has the trailing space.
"column " & "value " & include column by name "column " = plots are not shown
@skelliam Could you please confirm if you have the same behavior?
There was a problem hiding this comment.
Also you can execute project tests on Windows machine by modifying the Jenkinsfile:
buildPlugin(platforms: ['linux', 'windows'])
or
buildPlugin() // 'linux', 'windows' by default
To be honest, I'm not sure if they pass or fail, never tried on this project and we used 'linux' when Jenkinsfile was added in #31.
|
|
||
| private static final String[] FILES = {"test.csv"}; | ||
| private static final String[] FILES = {"test.csv", "spacestest.csv", "test_trailing_semicolon.csv"}; | ||
| private static final int[] LINES = {2, 3, 2}; //lines in the file including header |
There was a problem hiding this comment.
Comments should start with a space like // lines in ....
For some reason, this rule is also not enforced in tests.
| CSVSeries series = new CSVSeries(FILES[0], null, null, null, true); | ||
| assertTrue(series.getDisplayTableFlag()); | ||
| CSVSeries series; | ||
| for (int testfilenum = 0; testfilenum < FILES.length; testfilenum++) { |
There was a problem hiding this comment.
Please follow camelCase in variables naming.
-> testFileNumber.
| private static final int[] CORRECTED_COLS = {8, 3, 8}; //corrected for the trailing comma case | ||
| private static final int[] TOTAL_POINTS = {8, 6, 8}; //total data points in the file | ||
| private static final String[] LAST_COLUMN_NAME = {"error %", "thing", "error %"}; //the label on the last column | ||
| private static final String[] LAST_POINT = {"0.37", "42", "0.37"}; //the value of the last data point |
There was a problem hiding this comment.
Please remove unused constant.
| File workspaceDirFile = new File("target/test-classes/"); | ||
| FilePath workspaceRootDir = new FilePath(workspaceDirFile); | ||
| for (int testfilenum = 0; testfilenum < FILES.length; testfilenum++) { | ||
| // first create a FilePath to load the test Properties file. |
There was a problem hiding this comment.
Let's extract following code block into a separate method and reuse in tests:
// first create a FilePath to load the test Properties file.
File workspaceDirFile = new File("target/test-classes/");
FilePath workspaceRootDir = new FilePath(workspaceDirFile);
LOGGER.info("workspace File path: " + workspaceDirFile.getAbsolutePath());
LOGGER.info("workspace Dir path: " + workspaceRootDir.getName());
| LOGGER.info("Got " + points.size() + " plot points"); | ||
| testPlotPoints(points, TOTAL_POINTS[testfilenum]); | ||
|
|
||
| int pointnum = 0; |
There was a problem hiding this comment.
Please follow camelCase in variables naming.
-> pointNumber
-> columnNumber
|
@skelliam hey, are you still around? |
|
@vgaidarji Hey I'm still around, just haven't had much of a chance to get to this... Seems like trim() is a low risk addition though, and you found other cases where you could use trim() i.e. on the column name to include? |
|
@skelliam yes, let's fix the issues pointed above, try running tests on Windows slave (#45 (comment)), and we can merge this one. |
|
@skelliam are you still around? ^^ |
|
Holiday weekend here in the US. Maybe I can get to this this weekend? Sorry for no feedback. |
Codecov Report
@@ Coverage Diff @@
## master #45 +/- ##
=========================================
Coverage ? 42.06%
Complexity ? 178
=========================================
Files ? 18
Lines ? 1222
Branches ? 186
=========================================
Hits ? 514
Misses ? 644
Partials ? 64
Continue to review full report at Codecov.
|
|
@skelliam same question 🙂
|
|
Thanks @vgaidarji, sorry to have abandoned this, I made the changes at work and since then haven't been close to our Jenkins build. 🙏 |
|
@skelliam no problem, it's understandable 😉 Thanks for your contribution 💪 |

Use trim() on label values
Update test cases and test more than one csv file
Add test case that excludes only the last row
What has been done
Screenshots
Debugging in Visual Studio code, I took screenshots of the original code grabbing the trailing space from the new test case I added.
How to test
Checklist