Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reenable more tests #2371

Merged
merged 19 commits into from
Dec 22, 2016
Merged

Reenable more tests #2371

merged 19 commits into from
Dec 22, 2016

Conversation

stefan-kolb
Copy link
Member

@stefan-kolb stefan-kolb commented Dec 12, 2016

  • Corrections of wrong Bibtex serializations: I inverted the tests for the file field so they test if the fields are not changed for \n and \t.
  • Edge case behavior: Not implemented right now and won't be as @lenhard says. Removed for now until implemented.
  • Author parsing
    The result is: Expected :Other, A. N.; Actual :Other, Jr., A. N. We decided that this is expected behavior for now.
  • Layouter test: logic is just not handling \n\n to <br> conversion. Cannot be handled anymore as the BibTeX parser strips duplicated whitespaces by default!
  • XMP test: Fixed
  • OO test: Fixed
  • Ignored GUI tests: Will stay ignored for now.

@stefan-kolb
Copy link
Member Author

@lenhard You can probably comment a little bit on the test that were previously inside the parser.

@stefan-kolb
Copy link
Member Author

I tend to either fix the ignored tests or remove them. For some of them I don't even know what they should do...

@stefan-kolb
Copy link
Member Author

@JabRef/developers I need help from all of you that have expertise in at least one of these topics!

@tobiasdiez
Copy link
Member

The tests for the file field are a bit strange. I'm not sure why tabs and newlines are bad there. But, anyways, the parser shouldn't remove whitespace; this should be done in a separate cleanup.

The result of the author parsing also looks good to me (although one could argue that the Jr part is unimportant and should be deleted in an abbreviated representation...).

@koppor
Copy link
Member

koppor commented Dec 12, 2016

XMP: This is JabRef's implemenation to store BibTeX data inside PDFs to ease sharing of BibTeX data along with the PDF. Refs #938 #1096 (comment). Think, we have to switch to Dublin Core or to biblatexml. This takes more than a few hours. Since I am fan of this way of sharing, I'd like to keep the tests to be able to think of backward compatibility.

@lenhard
Copy link
Member

lenhard commented Dec 13, 2016

My 2 cents:

  • newline / tab elimination: That happens in FieldContentParser, which is called during parsing, and does work. However, the file field is explicitly exempted from this behavior, so the test fails (trying to fix the content of the file field is calling for problems). I think this should be changed to some other field, say title and the tests would be fine.
  • edge case: This is documented in Saved file cannot be read #1212 and does not work. With the current structure of the parser, this is also far from trivial, since it would need a lot of look-ahead in the parsing. My strategy has been to ignore it until some users actually complain about it. I would keep on doing that.
  • author parsing: No idea really, I would keep ignoring it.
  • The html stuff I am not sure as well. I haven't really touched those formatters so far.

@stefan-kolb
Copy link
Member Author

@lenhard Thanks for your input. So I just need to change the first tests to another field right now, e.g. title?!
I will remove the dge case then for now.
Looks like the author parser is correct.
So I'm just missing a resolution for the HTML and XMP stuff 😄 👍

@matthiasgeiger
Copy link
Member

However, the file field is explicitly exempted from this behavior, so the test fails (trying to fix the content of the file field is calling for problems). I think this should be changed to some other field, say title and the tests would be fine.

Or: Rewrite the tests to check that the content of the file field is NOT changed. @stefan-kolb You should check whether tests for these two aspects are already in place - if so, you can just delete the ignored ones

@lenhard
Copy link
Member

lenhard commented Dec 13, 2016

@stefan-kolb @matthiasgeiger If you invert the tests, then use either review or abstract. These are the only hard-coded fields where we avoid newline elimination. The other ones can be configured in the preferences and the file field is a default. But if a user really wants to, he can remove it from that list.

@stefan-kolb stefan-kolb added the status: ready-for-review Pull Requests that are ready to be reviewed by the maintainers label Dec 13, 2016
@stefan-kolb
Copy link
Member Author

stefan-kolb commented Dec 13, 2016

Ok, I fixed or removed all tests now. Only one ignored test is remianing in logic, which will be fixed by @matthiasgeiger in his custom entries PR?! The GUI tests still remain ignored.

Copy link
Member

@lenhard lenhard left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One minor thing (formatting) and one request for clarification.

public void testCommandLineByKey() throws IOException, TransformerException {

File tempBib = File.createTempFile("JabRef", ".bib");
try (BufferedWriter fileWriter = Files.newBufferedWriter(tempBib.toPath(), StandardCharsets.UTF_8)) {
fileWriter.write(t1BibtexString());
fileWriter.write(t2BibtexString());
fileWriter.close();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you need the close statement here? fileWrite is opened in a try-with-resources, so it will be closed at the end.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test fails if I do not close the current fileWriter. Maybe it would be betetr to extract the code below from the try statement...

public void testCommandLineByKey() throws IOException, TransformerException {

File tempBib = File.createTempFile("JabRef", ".bib");
try (BufferedWriter fileWriter = Files.newBufferedWriter(tempBib.toPath(), StandardCharsets.UTF_8)) {
fileWriter.write(t1BibtexString());
fileWriter.write(t2BibtexString());
fileWriter.close();

{ // First try canh05
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not your change, but why is this bracket opening in a new line? Can you fix the formatting in this method?

Copy link
Member Author

@stefan-kolb stefan-kolb Dec 13, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The bracket below? This is some old stuff. I already forgot what this does in Java...creates a new isolated scope or so...

@stefan-kolb
Copy link
Member Author

@lenhard Thanks for the review, some good input here!

this.prefs = Objects.requireNonNull(prefs);
this.encoding = StandardCharsets.UTF_8;
setDefaultProperties();
initialize(OOBibStyle.class.getResource(resourcePath).openStream());
initialize(OOBibStyle.class.getResourceAsStream(resourcePath));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

be aware that the inputstream is null if the resource cannot be found, resulting in a NPE.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this any different than before?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can wrap it inside Objects.requireNonNull() and also add some Objects.requireNonNull for resourcePath and prefs before lin 153

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added some requireNonNulls.

try {
XMPUtilMain.main(new String[]{"OezbekC06", tempBib.getAbsolutePath(), pdfFile.getAbsolutePath()});
} finally {
System.setOut(sysOut);
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For something like this, I would prefer to create a utility method that can be called. Should be useful on other occasions as well. You can pass in a lambda function which will be called from the utility method, and the method could simply return the value of the sysout as a String.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be honest, I didn't want to refactor the tests but just get them running again.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK for leave as is - I copied @simonharrer's comment to JabRef#6.

if (!tempBib.delete()) {
// TODO: file is still locked
System.err.println("Cannot delete temporary file");
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be either an assertion or deleted.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For some reason the file cannot be deleted and is still locked but I dunno where yet (and don't really care).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not just calling deleteOnExit()? This would prevent these kind of issues.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A better way to use a TemporaryFolder rule and create the file there. Then junit keeps track of deleting it

public void parseRemovesNewlineInFileField() throws IOException {
ParserResult result = BibtexParser.parse(new StringReader("@article{canh05,file = {ups \n\tsala}}"),
public void parsePreservesNewlineInAbstractField() throws IOException {
ParserResult result = BibtexParser.parse(new StringReader("@article{canh05,abstract = {ups \nsala}}"),
importFormatPreferences);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it make sense to create a BibtexParser.parse(string, prefs) method?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dunno, amybe @lenhard knows.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, it is what the BibtexParser.parse method does internally. If you parse multiple times subsequently, there might be a little performance impact, if you parse only once then it does not matter.

importFormatPreferences);

Collection<BibEntry> c = result.getDatabase().getEntries();
BibEntry e = c.iterator().next();
assertEquals(Optional.of("ups sala"), e.getField("file"));
assertEquals(Optional.of("ups " + OS.NEWLINE + "sala"), e.getField("abstract"));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have a constant for the abstract field somewhere?

// PDF should be annotated:
List<BibEntry> l = XMPUtil.readXMP(pdfFile, xmpPreferences);
Assert.assertEquals(1, l.size());
assertEqualsBibtexEntry(t1BibtexEntry(), l.get(0));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not like to assert the size of a list, because the result would simply say that the count mismatches, not which elements are in the list. Why not use the assertEqualsBibtexEntryList method if there is some which compares a list containing t1BibtexEntry with l?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I know there is no such method or maybe @tobiasdiez knows.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assert.assertEquals(Collections.singleton(tlBibtexEntry()), l) should work (and please rename l to something better :-)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Uhh... as this relies on the equals implemenation of BibEntry I'm not sure whether this really works. 😉

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, we wanted to use a canonical string representation for the bib entries.

The current implementation of BibEntryAssert also relies on equals so it is very much OK to use the code @tobiasdiez proposed.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does not work right now author is not normailzed or so:
Expected

[@article{canh05,
  author = {Crowston, K. and Annabi, H. and Howison, J. and Masango, C.},
  booktitle = {Hawaii International Conference On System Sciences (HICSS)},
  owner = {oezbek},
  timestamp = {2006.05.29},
  title = {Effective work practices for floss development: A model and propositions},
  url = {http://james.howison.name/publications.html},
  year = {2005}
}]

Actual

[@article{canh05,
  author = {K. Crowston and H. Annabi and J. Howison and C. Masango},
  booktitle = {Hawaii International Conference On System Sciences (HICSS)},
  owner = {oezbek},
  timestamp = {2006.05.29},
  title = {Effective work practices for floss development: A model and propositions},
  url = {http://james.howison.name/publications.html},
  year = {2005}
}]

I would skip this for now.

// PDF should be annotated:
l = XMPUtil.readXMP(pdfFile, xmpPreferences);
Assert.assertEquals(1, l.size());
assertEqualsBibtexEntry(t2BibtexEntry(), l.get(0));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See above.

Copy link
Member

@koppor koppor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general: LGTM

As usual, I vote for keeping and adapting tests. 😇 Find the comments inside. ☁️

@@ -176,7 +176,7 @@ private static void usage() {
System.out.println(" xmpUtil <bib> <pdf>");
System.out.println("");
System.out
.println("To report bugs visit http://jabref.sourceforge.net");
.println("To report bugs visit https://github.com/JabRef/jabref/issues");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://issues.jabref.org, pleae

this.prefs = Objects.requireNonNull(prefs);
this.encoding = StandardCharsets.UTF_8;
setDefaultProperties();
initialize(OOBibStyle.class.getResource(resourcePath).openStream());
initialize(OOBibStyle.class.getResourceAsStream(resourcePath));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can wrap it inside Objects.requireNonNull() and also add some Objects.requireNonNull for resourcePath and prefs before lin 153

@@ -786,19 +786,6 @@ public void parseWarnsAboutUnmatchedContentInEntry() throws IOException {
}

@Test
@Ignore("Ignoring because this is an edge case")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would like to know, what's happening here. Can the test be adapted to the current behavior and possibly commented, what should happen?

I would need that if someone comes over and wants to replace our parser 😇

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It just doesn't work right now as @lenhard says. So there is no sense to test it at the moment.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

JabRef returns one entry, which pretty good. I would like to have this checked in tests if we adress it.

The test has to be adapted accordingly.

Result is

@article{test, author = {author bracket #too##much#} }

Would it be OK if you include this as expected case, even if the } gets lost...

This documents the drawback of JabRef.

OK, additional documentation at https://help.jabref.org/en/Bibtex would be better, but none of us has time for that.

@@ -86,15 +82,6 @@ public void testHTMLChar() throws IOException {
}

@Test
@Ignore
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not adapting it to the current behavior? I think, we drop <br> now, which is fine. Why not leaving the additional test?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please do not delete the test. Just remove @Ignore and remove <br>.

grabbed_20161215-133111

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If that's really what we want to achieve here \n\n -> ' '
I'm not sure about this that's why I removed the test.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In other words: That is the current behavior, yes. But should it really be the correct behavior? In my opinion we should only test correct behavior not as is behavior. As the correct behavior for example
is not working right now I cannot really test it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think, we decided to remove newlines in non-multiline fields. Is it #357?

Even if that is not the desired behavior, I would add // TODO: The correct behavior is to indicate that someone should work on it.

Alternative: open an issue on GitHub. - I am currently optimizing (i) to keep the number of opened issues low and (ii) to have documentation close to the code and not spread around.

// PDF should be annotated:
List<BibEntry> l = XMPUtil.readXMP(pdfFile, xmpPreferences);
Assert.assertEquals(1, l.size());
assertEqualsBibtexEntry(t1BibtexEntry(), l.get(0));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, we wanted to use a canonical string representation for the bib entries.

The current implementation of BibEntryAssert also relies on equals so it is very much OK to use the code @tobiasdiez proposed.

if (!tempBib.delete()) {
// TODO: file is still locked
System.err.println("Cannot delete temporary file");
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not just calling deleteOnExit()? This would prevent these kind of issues.

try {
XMPUtilMain.main(new String[]{"OezbekC06", tempBib.getAbsolutePath(), pdfFile.getAbsolutePath()});
} finally {
System.setOut(sysOut);
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK for leave as is - I copied @simonharrer's comment to JabRef#6.

# Conflicts:
#	src/test/java/net/sf/jabref/logic/importer/fileformat/BibtexParserTest.java
@stefan-kolb stefan-kolb merged commit 5a5ff12 into master Dec 22, 2016
@stefan-kolb stefan-kolb deleted the enable-tests branch December 22, 2016 13:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: ready-for-review Pull Requests that are ready to be reviewed by the maintainers
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants