Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up test_parser.py, use xFail instead of skip where appropriate #1428

Merged
merged 3 commits into from
Jun 20, 2024

Conversation

MegaIng
Copy link
Member

@MegaIng MegaIng commented Jun 18, 2024

This is something I did while working on the Lark.scan implementation. I wanted to use xfail and decided that it should be quite useful for many other tests as well. I also deleted a few old comments/completely skipped tests suggesting features that will probably never be implemented.

I adjusted a few of the conditions based on the actual behavior of the code, for example cyk does actually support the tree less transformer argument. It doesn't have quite as big of a benefit, but it does work.

@erezsh
Copy link
Member

erezsh commented Jun 18, 2024

Why change the skip to xfail? xfail implies the test should be fixed in the future, i.e. failing for now but should work. (I'm sure you know pytest supports skip too)

Also, I'm wondering if this PR won't cause too many collisions with the lark.lark PR..

@MegaIng
Copy link
Member Author

MegaIng commented Jun 19, 2024

xfail implies the test should be fixed in the future, i.e. failing for now but should work

I somewhat disagree: While this is a possible meaning, I would in this case interpret it as these should fail, and if they don't the tests aren't actually testing for what they should, without any promises about the future. E.g. a test case that is designed to specifically need the dynamic lexer should not function without it. But if you are strongly against this interpretation, that's fine by me.

Also, I'm wondering if this PR won't cause too many collisions with the lark.lark PR..

I don't think so? That PR hasn't touched test_parser.py at all.

@erezsh
Copy link
Member

erezsh commented Jun 19, 2024

Oh right, sorry my bad.

As for xfail, I don't think it means that the test won't function, but rather that the test is correct but the source code isn't. So for example xfailing ambiguity on lalr would mean that we expect lalr to support ambiguity, and it's temporarily broken.

If it's not a bother, could you please change xfail into skip?

@MegaIng
Copy link
Member Author

MegaIng commented Jun 19, 2024

As for xfail, I don't think it means that the test won't function, but rather that the test is correct but the source code isn't. So for example xfailing ambiguity on lalr would mean that we expect lalr to support ambiguity, and it's temporarily broken.

This is a possible interpretation, and probably the more common one. But I don't think the feature itself is all too prescriptive in this regard.

As a concrete example, consider the tests that use the tree less transform parameter. These only work for lalr (and cyk) and should produce an error message for earley, meaning that the tests using this should not pass, i.e. they are expected to fail. We currently have no plans to ever implement this feature (AFAIK), but it's still an ok usecase of xfail IMO. If you think this is to confusing, I will revert that part of this PR.

@erezsh
Copy link
Member

erezsh commented Jun 19, 2024

Yes, using Earley in that case should produce an error, but usually that would be caught in an AssertRaises and not with the xfail mechanism.

But actually, if you feel strongly about it that's fine by me. I usually just use xfail as a loose TODO marking, so not much loss there.

Edit: I take it back. I just ran it in the console and got a huge wall of xfail warnings.. Let's just use skip, okay?

@MegaIng MegaIng mentioned this pull request Jun 20, 2024
3 tasks
@MegaIng
Copy link
Member Author

MegaIng commented Jun 20, 2024

Edit: I take it back. I just ran it in the console and got a huge wall of xfail warnings.. Let's just use skip, okay?

Sure, did that. Now it's a huge wall of skip warnings instead.

Copy link
Member

@erezsh erezsh left a comment

Choose a reason for hiding this comment

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

Thanks!

For whatever reason, the wall of skips is 3 times smaller than the wall of xfails was.

I also think to make it even less, by replacing a few of the skips with a simple if stmt. But I can do that later, after this has been merged.

tests/test_parser.py Outdated Show resolved Hide resolved
tests/test_parser.py Outdated Show resolved Hide resolved
tests/test_parser.py Outdated Show resolved Hide resolved
@erezsh erezsh merged commit 8611d69 into lark-parser:master Jun 20, 2024
10 checks passed
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.

2 participants