hRobert12 / mock

Automatically exported from code.google.com/p/mock
BSD 2-Clause "Simplified" License
0 stars 0 forks source link

Strange behavior in callargs #112

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
I have a test that checks call_args_list using indexes like this:

    self.assertEqual(survey.setSession.call_args_list[0][0], ('title', 'Thank you for taking the survey'))
    self.assertEqual(survey.setSession.call_args_list[1][0], ('body', ''))

This is done because there are multiple calls to survey.setSession which needs 
to be checked. Probably I shouldn't do it like that, but it was the quickest 
way to check multiple calls.

Since I've updated to the new mock version (0.8) this fails because the first 
argument element in the tuple appears to be an empty string (name variable).

Also I've noticed that __repr__ from callargs does this:

    return tuple.__repr__(self[1:]) 

hiding the first element from the representation which confused me even further.

Here is a pdb session:

    (Pdb) survey.setSession.call_args_list[0]
    (('title', 'Thank you for taking the survey'), {})
    (Pdb) survey.setSession.call_args_list[0][0]
    ''

This is inconsistent.

Original issue reported on code.google.com by alexandr...@gmail.com on 27 Jul 2011 at 8:40

GoogleCodeExporter commented 8 years ago
Yes, this is a backwards incompatibility introduced in mock 0.8.0 beta 1. I've 
fixed this in the repository and will release a new beta soon. My apologies. 

Original comment by fuzzyman on 27 Jul 2011 at 10:22

GoogleCodeExporter commented 8 years ago
Note that if you *want* to carry on using the beta you can use the [-2] index 
(from the end instead of the start) which will be compatible with both the 
broken beta 1 and earlier / later fixed versions. It's not a nice hack though.

Original comment by fuzzyman on 27 Jul 2011 at 10:26

GoogleCodeExporter commented 8 years ago
I've switched to 0.7.2 right now. I'll wait for the next release. Thanks a lot.

Original comment by meph...@gmail.com on 27 Jul 2011 at 10:33