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

Combinating composition and conditional operators does not work #41

Open
jcassee opened this issue Apr 28, 2018 · 2 comments
Open

Combinating composition and conditional operators does not work #41

jcassee opened this issue Apr 28, 2018 · 2 comments
Labels

Comments

@jcassee
Copy link
Contributor

jcassee commented Apr 28, 2018

Not sure if this is expected to work, but I had hoped to combine composition and conditional operators:

from grappa import *

{1: {2: 3}} | should.have.key(1) > should.have.key(2) > should.equal(3)

{1: {2: 3}} | should.have.key(1) > should.all(should.have.key(2) > should.equal(3))
AssertionError: Oops! Something went wrong!

  The following assertion was not satisfied
    subject "Empty" should equal 3

  What we expected
    a value that is equal to "3"

  Difference comparison
    > - Empty
    > + 3

  Where
    File "/home/joost/Ontwikkeling/GoAbout/pacioli/grappa-test.py", line 7, in <module>

     1|   #!/usr/bin/env python
     2|   
     3|   from grappa import *
     4|   
     5|   {1: {2: 3}} | should.have.key(1) > should.have.key(2) > should.equal(3)
     6|   
     7| > {1: {2: 3}} | should.have.key(1) > should.any(should.have.key(2) > should.equal(3))
     8|   
@h2non
Copy link
Member

h2non commented May 1, 2018

Because of the operator precedence in Python and some inherent complexity with lazy evaluation in such case, it's not currently possible using > yield test subject operator in conditional composition. I think I can find a way to make it work, but I can't spend time on that right now.

The recommended style here that actually works is using the yield chain operator instead:

{1: {2: 3}} | should.have.key(1) > should.any(
   should.have.key(2).that.should.be.equal(3),
   should.have.key(2).that.should.be.empty)

@h2non h2non added the question label May 1, 2018
@jcassee
Copy link
Contributor Author

jcassee commented May 3, 2018

Thanks, Tomás, I can use that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants