rfhub2 icon indicating copy to clipboard operation
rfhub2 copied to clipboard

Refactor statistics extractor to use Robot API visitor

Open bhirsz opened this issue 4 years ago • 6 comments

It's proposal of refactor for extracting keywords from result using Robot parsing API visitors.

It should be tiny bit faster on larger files (150Mb+). I did not test it thorougly yet - it's draft.

bhirsz avatar Feb 23 '21 13:02 bhirsz

Thanks @bhirsz, it looks good! If you could also add tests for that it would be great.

pbylicki avatar Mar 10 '21 21:03 pbylicki

@bhirsz I was looking into that one, and one thing is bottering me. Which robotframework version is intended to use with this feature? 3.2.2 seems to be not enough:

File "C:\repo\rfhub2\rfhub2\cli\statistics\statistics_extractor.py", line 15, in visit_keyword
    keyword.body.visit(self)
AttributeError: 'Keyword' object has no attribute 'body'

If this feature needs RFWK 4.0 I will mark it appropriate Milestone.

MaciejWiczk avatar Mar 21 '21 14:03 MaciejWiczk

@MaciejWiczk I apologise for leaving this PR - I was bit busy recently. It should support 3.2 with one change - in RF4 "keywords" attribute was renamed to body. So depending on version you should access it with different name

bhirsz avatar Mar 21 '21 14:03 bhirsz

But when I think about it its possible we could replace that line with self.generic_visit (and it should work for both 3.2 and 4)

bhirsz avatar Mar 21 '21 14:03 bhirsz

I apologise for leaving this PR - I was bit busy recently.

You've been busy, with great results! :)

But when I think about it its possible we could replace that line with self.generic_visit (and it should work for both 3.2 and 4)

Oh cool, I will take a look at this approach and see what's what :)

MaciejWiczk avatar Mar 22 '21 10:03 MaciejWiczk

@bhirsz is this what You mean:

    def visit_keyword(self, keyword):
        try:
            keyword.body.visit(self)
        except AttributeError:
            keyword.keywords.visit(self)
        self.statistics[keyword.name].append(keyword)

MaciejWiczk avatar Mar 22 '21 12:03 MaciejWiczk