syntactic sugar

7 views
Skip to first unread message

szczepiq

unread,
Jul 20, 2008, 6:29:04 AM7/20/08
to mockito...@googlegroups.com
Can we have in Python syntactic sugar ala Ruby?

2.times
3.times

so that:

verify(mock, 2.times).foo()

Bartosz Bańkowski

unread,
Jul 20, 2008, 1:33:13 PM7/20/08
to mockito...@googlegroups.com
To omit parenthesis you can do something like that:

def a():
return 1

b = a()

b

But if you want to add a method to int class you get a nice error:

TypeError: can't set attributes of built-in/extension type 'int'

Simon Brunning

unread,
Aug 14, 2008, 4:24:47 AM8/14/08
to mockito-python
This won't work for so many reasons it's not true. Even times.2
wouldn't get parsed properly. What's wrong with times(2)? This is
Python - we'll have none of your rubyesqe "never mind seeing if the
existing syntax will work - let's build a DSL!" here, thank you. ;-)

Cheers,
Simon B.
si...@brunningonline.net
http://www.brunningonline.net/simon/blog/
GTalk: simon.brunning | MSN: small_values | Yahoo: smallvalues |
Twitter: brunns

szczepiq

unread,
Aug 14, 2008, 10:26:22 AM8/14/08
to mockito...@googlegroups.com
c'mon, don't tell me you don't like 3.times sugar. It's just beautiful :)

I went for times(2). We could discuss the best syntax forever and
still whatever we chose, times(x) is still used occasionally.

Here are all the cool ways I considered (and there are probably plenty more):

verify(mock, times(3)).foo()
verify(mock, _3.times).foo()
verify(mock, x3).foo()
verify(mock, x3.times).foo()
verify(mock).foo().times(3)

Yet, I decided to go for good old times(x)

cheers,
Szczepan

Bartosz Bańkowski

unread,
Aug 15, 2008, 5:56:50 AM8/15/08
to mockito...@googlegroups.com
Don't forget about my favorite:

verify(mock, times=3).foo()

Reply all
Reply to author
Forward
0 new messages