Unit testing errors (testing the platform module)
J. Cliff Dyer
jcd at sdf.lonestar.org
Wed Apr 14 11:19:47 EDT 2010
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__)
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
Admittedly, this is a trivial benefit. If you're using a literal, you
already know what type you're dealing with.
Cheers,
Cliff
More information about the Python-list
mailing list