This repository was archived by the owner on May 5, 2025. It is now read-only.
Do not consider method-lines as relevant in cobertura#1170
Open
Do not consider method-lines as relevant in cobertura#1170
Conversation
The etree API is a bit weird, because the `iter()` method will iterate over matching elements in the whole subtree, instead of only over child elements. Which we actually use extensively, as we are not fully traversing the xml structure of the various formats, but just iterate over the relevant elements, regardless of their nesting. However for cobertura this might not be the right thing to do. As a `class` can have `lines>line`, but also a `class>methods>method` can have `lines>line` as well. We are only interested in the directly declared `lines>line`, not the ones nested within `methods` however. --- Along with fixing this for the cobertura processor, this also changes some tests to use the proper class. We use the `lxml` library in production, but a ton of tests were using the `xml` library, which has a mostly compatible API, but differs in some small details. For example, `lxml` has the `iterchildren` method, while `xml` does not. Along with changing to the proper `lxml` library, some tests also changed their inputs to `bytes`, as the `lxml` library is otherwise throwing an error when trying to parse an xml declaration that defines an `encoding` from a python `str`, which is utf-8 by definition.
Contributor
✅ Sentry found no issues in your recent changes ✅ |
Codecov ReportAll modified and coverable lines are covered by tests ✅
✅ All tests successful. No failed tests found. Additional details and impacted files@@ Coverage Diff @@
## main #1170 +/- ##
==========================================
- Coverage 97.72% 97.72% -0.01%
==========================================
Files 449 449
Lines 36864 36866 +2
==========================================
+ Hits 36026 36027 +1
- Misses 838 839 +1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
Codecov ReportAll modified and coverable lines are covered by tests ✅ ✅ All tests successful. No failed tests found. 📢 Thoughts on this report? Let us know! |
giovanni-guidini
approved these changes
Mar 24, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The etree API is a bit weird, because the
iter()method will iterate over matching elements in the whole subtree, instead of only over child elements. Which we actually use extensively, as we are not fully traversing the xml structure of the various formats, but just iterate over the relevant elements, regardless of their nesting.However for cobertura this might not be the right thing to do. As a
classcan havelines>line, but also aclass>methods>methodcan havelines>lineas well. We are only interested in the directly declaredlines>line, not the ones nested withinmethodshowever.Along with fixing this for the cobertura processor, this also changes some tests to use the proper class. We use the
lxmllibrary in production, but a ton of tests were using thexmllibrary, which has a mostly compatible API, but differs in some small details. For example,lxmlhas theiterchildrenmethod, whilexmldoes not.Along with changing to the proper
lxmllibrary, some tests also changed their inputs tobytes, as thelxmllibrary is otherwise throwing an error when trying to parse an xml declaration that defines anencodingfrom a pythonstr, which is utf-8 by definition.