Unit testing errors (testing the platform module)

Terry Reedy tjreedy at udel.edu
Wed Apr 14 18:31:20 CEST 2010


On 4/14/2010 11:19 AM, J. Cliff Dyer wrote:
> On Wed, 2010-04-14 at 15:51 +0100, john maclean wrote:
>> self.assertEqual(platform.__builtins__.__class__, dict,
>> "platform.__class__ supposed to be dict")
>> self.assertEqual(platform.__name__, 'platform' )
>
> The preferred spelling for:
>
>      platform.__builtins__.__class__
>
> would be
>
>      type(platform.__builtins__)

Agreed

> It's shorter and easier to read, but essentially says the same thing.
>
> You can also use it on integer literals, which you can't do with your
> syntax:
>
>      >>>  type(1)
>      <type 'int'>
>      >>>  1.__class__
>      ...
>      SyntaxError: invalid syntax

Add the needed space and it works fine.

 >>> 1 .__class__
<class 'int'>

A possible use of literal int attributes is for bound mehods:

 >>> inc = 1 .__add__
 >>> inc(3)
4
 >>> inc(3.0)
NotImplemented

Whereas def inc(n): return n+1 is generic and would return 4.0.

Terry Jan Reedy




More information about the Python-list mailing list