Unit testing errors (testing the platform module)

john maclean jayeola at gmail.com
Wed Apr 14 16:51:55 CEST 2010


On 14 April 2010 09:09, Gabriel Genellina <gagsl-py2 at yahoo.com.ar> wrote:
> En Tue, 13 Apr 2010 11:01:19 -0300, John Maclean <jayeola at gmail.com>
> escribió:
>
>> Is there an error in my syntax? Why is my test failing? Line 16.
>>
>> ======================================================================
>> FAIL: platform.__builtins__.blah
>> ----------------------------------------------------------------------
>> Traceback (most recent call last):
>>  File "stfu/testing/test_pyfactor.py", line 16, in testplatformbuiltins
>>    self.assertEquals(platform.__builtins__.__class__, "<type 'dict'>")
>> AssertionError: <type 'dict'> != "<type 'dict'>"
>>
>> ----------------------------------------------------------------------
>
> To express the condition "SOMEOBJECT must be a dictionary", use:
>
>    isinstance(SOMEOBJECT, dict)
>
> SOMEOBJECT might actually be an instance of any derived class and still pass
> the test; that's usually the desired behavior.
>
> In the rare cases where only a very specific type is allowed, use this form
> instead:
>
>    type(SOMEOBJECT) is dict
>
>
> The test case above should read then:
>
>    self.assert_(isinstance(platform.__builtins__, dict),
>                 type(platform.__builtins__))
>
> --
> Gabriel Genellina
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>

This is cool. Thanks for your replies.

self.assertEqual(platform.__builtins__.__class__, dict,
"platform.__class__ supposed to be dict")
self.assertEqual(platform.__name__, 'platform' )


-- 
John Maclean
07739 171 531
MSc (DIC)

Enterprise Linux Systems Engineer



More information about the Python-list mailing list