derwiki-adroll / mock

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

mock.Mock() objects should support __name__ overriding as well as have a default __name__ #67

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?

>>> import mock
>>> m = mock.Mock()
>>> print m.__name__
Traceback (most recent call last):
...
AttributeError: __name__

What is the expected output? What do you see instead?

Something other than AttributeError

What version of the product are you using? On what operating system?

v0.7b4

Please provide any additional information below.

There should be a default __name__ and Mock should support overriding __name__

Original issue reported on code.google.com by mabdelka...@gmail.com on 10 Feb 2011 at 5:33

GoogleCodeExporter commented 9 years ago
I agree that it should be possible to *set* __name__. What should it be by 
default though? (Note that most objects don't have a __name__ - classes do 
though.)

Original comment by fuzzyman on 10 Feb 2011 at 11:23

GoogleCodeExporter commented 9 years ago
You're absolutely right in that most objects don't have a __name__, but for the 
most parts, functions and classes do have the __name__ attribute which I would 
assume would be the main use case for Mock. 

Now that I think about it, maybe default __name__ might not be a good idea, but 
at least the ability to support it would make sense. However, if we were to 
decide to allow a default name, then I would assume something similar to 
MockObject or maybe even whatever the __repr__ might be.

Thoughts?

Original comment by mabdelka...@gmail.com on 21 Feb 2011 at 7:33

GoogleCodeExporter commented 9 years ago
Well, in terms of "supporting it", you can already set __name__ to a string on 
a mock (I thought it might not be possible but it is). Beyond that I'm not sure 
what we could do to support it.

Original comment by fuzzyman on 22 Feb 2011 at 8:26

GoogleCodeExporter commented 9 years ago
Note that mock instances are just as commonly used to mock instances and so 
shouldn't have a __name__ by default. Setting it if you need it works. 

Any concrete proposals as to *changes* in Mock you can suggest?

If not I'll close this issue. 

Original comment by fuzzyman on 6 May 2011 at 11:59

GoogleCodeExporter commented 9 years ago

Original comment by fuzzyman on 14 May 2011 at 11:48