aconrad / pycobertura

A code coverage diff tool for Cobertura reports
MIT License
116 stars 39 forks source link

Can I use it with preload xml content? #102

Closed williamfzc closed 4 years ago

williamfzc commented 4 years ago

Hi there, good project!

In my cases, I used some snippets to convert lcov xml to Cobertura XML. And it will generate xml-format string.

converter = LcovCobertura(info_content)
cobertura_xml = converter.convert()

# now I have a xml-format string

So can we directly use xml-format string (rather than write it to file and read from it in pycobertura)? Or if you prefer a PR? :)

aconrad commented 4 years ago

I'm sure we can change that in some way to to prevent you from doing this intermediary step. It wasn't designed to support this use case but I'm sure we could accommodate without too much fuss. Have you looked at the code to see if there are opportunities for improvement?

williamfzc commented 4 years ago

Have you looked at the code to see if there are opportunities for improvement?

yep, I think it may be not that hard. (it looks like)

https://github.com/aconrad/pycobertura/blob/cdce1ae0eacd6d8b2954d289a2379330967abf97/pycobertura/cobertura.py#L40

xml content will be parsed at the beginning of __init__. We can add a pre-check here to identify if it is a valid xml-string. If it is not, treat it as a path.

draft:

https://github.com/williamfzc/pycobertura/commit/bf195cd0a67ea7e0c4b68baae60eac5b95ba9574

aconrad commented 4 years ago

Thanks for this @williamfzc! Can you please submit a PR so we follow the standard code reviewing process?

williamfzc commented 4 years ago

Thanks for this @williamfzc! Can you please submit a PR so we follow the standard code reviewing process?

Sure :) see #103

aconrad commented 4 years ago

Addressed in #103, closing.