Abuse with statement for Konira-inspired DSL #101

Open
dag opened this Issue Apr 27, 2011 · 5 comments

Comments

Projects
None yet
2 participants
@dag
Owner

dag commented Apr 27, 2011

Konira:

describe "a very simple test case for my_module":

    it "has a foo property that is False":
        assert my_module.foo == False

I think something similar could be achieved in Python by abusing the with statement:

with description('a very simple test case for my_module'):

    with expectation('has a foo property that is False'):
        assert my_module.foo == False

It's probably a bad idea but it is an idea so I'm saving it here.

Implications:

  • If modules are used as containers, the tests would run on import and probably need special-casing
  • Fixtures would either need to encapsule expectations or be passed to description or maybe something crazy using decorators on something description returns:
with description() as case:
    @case.context
    def fixture():
        yield

Benefits?

  • Maybe more "BDD"
  • Maybe cleaner syntactically, for reading and writing
  • Encourages descriptions for tests over simply function names
@dag

This comment has been minimized.

Show comment Hide comment
@dag

dag Apr 27, 2011

Owner

Let's shamelessly summon @alfredodeza to hear if he has any specific reasons for not going with this originally for Konira.

Owner

dag commented Apr 27, 2011

Let's shamelessly summon @alfredodeza to hear if he has any specific reasons for not going with this originally for Konira.

@dag

This comment has been minimized.

Show comment Hide comment
@dag

dag Apr 27, 2011

Owner

(Not suggesting you should, rather, curious if you thought of it and dismissed it and why.)

Owner

dag commented Apr 27, 2011

(Not suggesting you should, rather, curious if you thought of it and dismissed it and why.)

@alfredodeza

This comment has been minimized.

Show comment Hide comment
@alfredodeza

alfredodeza Apr 27, 2011

There are a couple of things to cover here, starting with the use of with statements in Konira.

This was coincidentally the first approach to make Konira work, take a look at https://gist.github.com/828739 which describes a bit what I was trying to do.

I got it to a working state and started using it a bit.

So what happened?

When a file had a few tests, it looked weird. When I was showcasing the prototype to my coworkers and friends they all were quick to say "this looks good but all these with statements... weird".

Secondly, and this is were I have to disagree with you, is that it was not readable at all. The current approach is way more readable, albeit at the expense of having a DSL structure to support it. But any newcomer to testing, can read and understand better what is going on compared to the with statement one.

I don't see Konira as it is now as less BDD because of it, but rather, the other way around.

It is funny how you thought about it, as like I mentioned before, it was the first try at getting it to work.

Hope you find my input valuable enough. I would be willing to discuss it further though. I try to avoid closing possible
options/implementations, specially with something so new as Konira.

There are a couple of things to cover here, starting with the use of with statements in Konira.

This was coincidentally the first approach to make Konira work, take a look at https://gist.github.com/828739 which describes a bit what I was trying to do.

I got it to a working state and started using it a bit.

So what happened?

When a file had a few tests, it looked weird. When I was showcasing the prototype to my coworkers and friends they all were quick to say "this looks good but all these with statements... weird".

Secondly, and this is were I have to disagree with you, is that it was not readable at all. The current approach is way more readable, albeit at the expense of having a DSL structure to support it. But any newcomer to testing, can read and understand better what is going on compared to the with statement one.

I don't see Konira as it is now as less BDD because of it, but rather, the other way around.

It is funny how you thought about it, as like I mentioned before, it was the first try at getting it to work.

Hope you find my input valuable enough. I would be willing to discuss it further though. I try to avoid closing possible
options/implementations, specially with something so new as Konira.

@dag

This comment has been minimized.

Show comment Hide comment
@dag

dag May 1, 2011

Owner

Thanks for responding!

  • By readable, I meant more (and only maybe) than the existing Flask-like API in Attest, not really compared to Konira
  • Similarly, "more BDD" was compared to current Attest, not Konira :)

I think people could learn and get used to 'with'. We're programmers, eh. The question is whether it makes semantic sense to use context managers here; I think it might but not sure. It does feel abusive but not "wrong".

Did you reject it on any technical grounds as well?

Owner

dag commented May 1, 2011

Thanks for responding!

  • By readable, I meant more (and only maybe) than the existing Flask-like API in Attest, not really compared to Konira
  • Similarly, "more BDD" was compared to current Attest, not Konira :)

I think people could learn and get used to 'with'. We're programmers, eh. The question is whether it makes semantic sense to use context managers here; I think it might but not sure. It does feel abusive but not "wrong".

Did you reject it on any technical grounds as well?

@alfredodeza

This comment has been minimized.

Show comment Hide comment
@alfredodeza

alfredodeza May 1, 2011

I quite like with statements, but the abuse, just like anything that gets abused in fact, looks odd/weird.

I'm sure it is not a learning curve to avoid, but rather how does with looks, and reads with the task we are trying to accomplish. In this case, to make BDD or readable tests cases.

And yes, I had to reject it on technical grounds at the end because I had a lot of difficulty trying to get the flexibility the current Konira implementation offers. I wouldn't be able to pin-point to it exactly since it has been a few months since I tried it and it was a temporary "let's try this" situation and not a long-term commitment.

It may have been something to do with nested with statements that everything started to represent a code nightmare :)

I quite like with statements, but the abuse, just like anything that gets abused in fact, looks odd/weird.

I'm sure it is not a learning curve to avoid, but rather how does with looks, and reads with the task we are trying to accomplish. In this case, to make BDD or readable tests cases.

And yes, I had to reject it on technical grounds at the end because I had a lot of difficulty trying to get the flexibility the current Konira implementation offers. I wouldn't be able to pin-point to it exactly since it has been a few months since I tried it and it was a temporary "let's try this" situation and not a long-term commitment.

It may have been something to do with nested with statements that everything started to represent a code nightmare :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment