Skip to content

checkPot: Add unit tests#11179

Merged
feerrenrut merged 3 commits into
nvaccess:masterfrom
accessolutions:i11071-checkPot-test
Jun 3, 2020
Merged

checkPot: Add unit tests#11179
feerrenrut merged 3 commits into
nvaccess:masterfrom
accessolutions:i11071-checkPot-test

Conversation

@JulienCochuyt

Copy link
Copy Markdown
Contributor

Link to issue number:

Follow-up of PR #11093

Summary of the issue:

PR #10941 brought to light flaws in checkPot regarding handling of long messages - fixed by PR #11093
@feerrenrut requested in #11093 (comment) the creation of unit tests to help limit occurrence of future regressions.

Description of how this pull request fixes the issue:

Added 6 unit tests for checkPot, namely:

  • Test that missing translators comment on the first message are reported.
  • Test that missing translators comment on the last message are reported.
  • Test that missing translators comment on short messages are reported.
  • Test that missing translators comment on long messages are reported.
  • Test that expected errors are reported as such.
  • Test that unexpected successes are reported as such.

Testing performed:

Well, for one thing... ran the unit tests!
More seriously, checked the test did fail when altering their input data and their expected output.

Known issues with pull request:

Change log entry:

I don't think this deserves a change log entry.

@feerrenrut feerrenrut left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It's not clear to me if there is a test here that checks for success specifically. IE. not an error, not an unexpected success, and not an expected error. I can see that there could be, but it might be helpful if this was "called out" explicitly.

Comment thread tests/unit/test_checkPot/__init__.py Outdated
def test_checkPot_lastMessage(self):
"""Test that missing translators comment on the last message are reported."""
self.assertEqual(
self.doCheckPot("firstMessage.pot"),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think these tests would be easier to read if the test data was inline, preferably using a template so that just the test specific data is visible. On the other hand it's probably a good thing that this tests it end to end.

@JulienCochuyt JulienCochuyt Jun 3, 2020

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Not easy to do without refactoring checkPot itself, as it currently only takes a filename parameter.
Furthermore, the test data currently sums up to 208 lines, which IMHO would reduce a whole lot the readability of the 98 lines long code.
Please note that the header of each data file also describes what errors are expected to be found in it.

EDIT: Sorry I over-read your comment. Templating would surely reduce the data footprint. Still checkPot only takes a filename, and I guess we are in no urge to refactor this.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I agree for now this is fine. Mostly I'm thinking about the ease of reading the tests, going back and forth to data files to understand the cases being tested can be a pain. One benefit of succinct unit tests is the way they document code to developers, and invite developers to add variations to understand how the code works under different circumstances.

@JulienCochuyt

Copy link
Copy Markdown
Contributor Author

@feerrenrut wrote:

It's not clear to me if there is a test here that checks for success specifically. IE. not an error, not an unexpected success, and not an expected error. I can see that there could be, but it might be helpful if this was "called out" explicitly.

Added an "allOk" test case: a38bb20

@feerrenrut feerrenrut left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@feerrenrut feerrenrut merged commit f2cbfec into nvaccess:master Jun 3, 2020
@nvaccessAuto nvaccessAuto added this to the 2020.2 milestone Jun 3, 2020
@JulienCochuyt JulienCochuyt deleted the i11071-checkPot-test branch June 3, 2020 11:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants