Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Using Comparitors in assertions.
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  4 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Simon Brunning  
View profile  
 More options Aug 19 2008, 3:38 pm
From: Simon Brunning <simon.brunn...@gmail.com>
Date: Tue, 19 Aug 2008 12:38:14 -0700 (PDT)
Local: Tues, Aug 19 2008 3:38 pm
Subject: Using Comparitors in assertions.
I'd really like to be able to use Mox's comparitors in assertions, as
well at in mock setup, so, for instance, I could do something like:

self.mox.AssertThat(revisions, mox.SameElementsAs([123, 456, 789]))

Whereas I think I have to do:

self.assertEquals(revisions, [123, 456, 789])

This doesn't read as well, and is more fragile. The right set of
Comparitors  - ContainsAllOf, ContainsInOrder, ContainsNoneOf for
example - makes for expressive tests.

Hmmm. Perhaps this doesn't belong in Mox, though. EasyMock uses
Hamcrest to provide this sort of functionality, so perhaps Mox needs
Spamcrest! There's a project to keep me out of trouble for a while.

Thoughts?

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


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Manuel Holtgrewe  
View profile  
 More options Aug 19 2008, 3:45 pm
From: Manuel Holtgrewe <zyklenf...@googlemail.com>
Date: Tue, 19 Aug 2008 21:45:24 +0200
Local: Tues, Aug 19 2008 3:45 pm
Subject: Re: [mox-discuss] Using Comparitors in assertions.
Hi Simon.

In the past, I extended unittest.TestCase for my project and added  
things like

def assertSetEquals(self, left, right, msg)
   self.assertEquals(set(self), set(right),
     msg or ('Iterables %s and %r do not contain different elements' %  
(left, right))

I guess you could implement the assertions mentioned below using  
list() constructors and set operations.

HTH
Manuel

Am 19.08.2008 um 21:38 schrieb Simon Brunning:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
steve middlekauff  
View profile  
 More options Aug 19 2008, 5:14 pm
From: "steve middlekauff" <smidd...@gmail.com>
Date: Tue, 19 Aug 2008 14:14:16 -0700
Local: Tues, Aug 19 2008 5:14 pm
Subject: Re: [mox-discuss] Re: Using Comparitors in assertions.
You can use Comparators in your assertions, as long as you are careful
to keep them on the LHS (you may or may not get some strange behavior
otherwise).

def testUsingComparatorsInAssertions(self):
  self.assertEquals(mox.IsA(str), "test string)

... or for your example ...

self.assertEquals(mox.SameElementsAs([123, 456, 789]), revisions)

I'm not sure if this is as expressive as you'd like, but it gets the
job done. :)

On Tue, Aug 19, 2008 at 12:45 PM, Manuel Holtgrewe

--
Steve Middlekauff
smidd...@gmail.com

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Simon Brunning  
View profile  
 More options Aug 19 2008, 10:04 pm
From: Simon Brunning <simon.brunn...@gmail.com>
Date: Tue, 19 Aug 2008 19:04:33 -0700 (PDT)
Local: Tues, Aug 19 2008 10:04 pm
Subject: Re: Using Comparitors in assertions.
On Aug 19, 10:14 pm, "steve middlekauff" <smidd...@gmail.com> wrote:

> You can use Comparators in your assertions, as long as you are careful
> to keep them on the LHS (you may or may not get some strange behavior
> otherwise).

> def testUsingComparatorsInAssertions(self):
>   self.assertEquals(mox.IsA(str), "test string)

> ... or for your example ...

> self.assertEquals(mox.SameElementsAs([123, 456, 789]), revisions)

> I'm not sure if this is as expressive as you'd like, but it gets the
> job done. :)

It certainly does. That's really nice.

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »