convert all tests to pytest - #311
Conversation
- test_align_cli: several conversions by hand - sub self.assertTrue\((.*)\)$ to assert $1 - sub self.assertEqual\(([^,]*), ([^,]*)\)$ by assert $1 == $2
sub self.assertFalse\((.*)\)$ by assert not $1 sub self.assertNotEqual\(([^,]*), ([^,]*)\)$ by assert $1 != $2 sub self.assertNotIn\(([^,]*), ([^,]*)\)$ by assert $1 not in $2 sub self.assertIsNotNone\(([^,]*)\)$ by assert $1 is not None sub with self.assertRaises\(([^,]*)\): by with raises($1):
including sub self.assertGreater\(([^,]*), ([^,]*)\)$ by assert $1 > $2 sub self.assertIsNone\(([^,]*)\)$ by assert $1 is None and a bunch more
Done with the help of GPT 5.6 Luna, with proposed changes reviewed line-by-line by Eric Joanis, and code adjusted where needed.
Changed Files
|
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #311 +/- ##
=======================================
Coverage 93.76% 93.76%
=======================================
Files 21 21
Lines 1765 1765
Branches 295 295
=======================================
Hits 1655 1655
Misses 73 73
Partials 37 37 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
|
||
| def test_non_convertible_words(self): | ||
| xml = parse_xml("<s><w>43:23</w><w>65:67</w><w>43:23</w></s>") | ||
| with self.assertLogs(LOGGER, level="WARNING"): |
There was a problem hiding this comment.
any reason this is removed?
There was a problem hiding this comment.
This is one of the many cases where I was using assertLogs to hide the massive output we used to get to terminal with unittest. I've never cared whether this logged, and still don't, the relevant assertions are on the next two lines.
There was a problem hiding this comment.
With pytest, it captures everything for us, so all the trouble I went to to reduce output is no longer needed. And by removing this nonsense, should you want to see that output, you are able to get it with pytest -s, instead of having to change the test code to stop hiding it.
| assert words[0]["end"] <= 1.62 | ||
| assert words[1]["start"] >= 1.62 | ||
| assert words[8]["end"] <= 3.81 | ||
| assert words[9]["start"] >= 3.81 |
There was a problem hiding this comment.
why'd this get changed from 3.82 to 3.81?
There was a problem hiding this comment.
Good catch, I must have thought it was a typo when I converted, but in fact the input data file has two anchors, one at 3.81 and one at 3.82, and the original assertions were correct. I'll fix this one.
PR Goal?
Wrapped up work mostly done in July: convert all tests to pytest, no more use of unittest at all.
As you can see in the commit logs, I used various regular expressions and some manual conversions in July, which was more efficient than all manual, but still time consuming. Now I decided to experiment with Codex on a simple task, and finished it all very quickly with the help of GPT 5.6 Luna, with a full line-by-line review of all proposed changes, rejecting and/or fixing what I didn't agree with.
Fixes?
Out with unittest!
Feedback sought?
normal review
Priority?
low
Tests added?
nothing but!
How to test?
uv run pytestConfidence?
high
Version change?
no