Unit testing errors (testing the platform module)

Benjamin Kaplan benjamin.kaplan at case.edu
Tue Apr 13 16:12:54 CEST 2010


On Tue, Apr 13, 2010 at 10:01 AM, John Maclean <jayeola at gmail.com> wrote:

> I normally use  languages unit testing framework to get a better
> understanding of how a language works. Right now I want to grok the
> platform module;
>
>
>  1 #!/usr/bin/env python
>  2 '''a pythonic factor'''
>  3 import unittest
>  4 import platform
>  5
>  6 class TestPyfactorTestCase(unittest.TestCase):
>  7     def setUp(self):
>  8         '''setting up stuff'''
>  13
>  14     def testplatformbuiltins(self): 15
> '''platform.__builtins__.blah '''
>  16         self.assertEquals(platform.__builtins__.__class__, "<type 'd
>    ict'>")
>  17
>  18
>  19     def tearDown(self):
>  20         print 'cleaning stuff up'
>  21
>  22 if __name__ == "__main__":
>  23     unittest.main()
>
>
> Is there an error in my syntax? Why is my test failing? Line 16.
>
>
Because you are checking if the type object dict is equal to the str object
"<type 'dict'>". A type object will never compare equal to a str object,
even though the string representation of them is the same.

>>> type({}) == "<type 'dict'>"
False
>>> type({})
<type 'dict'>
>>> str(type({})) == "<type 'dict'>"
True
>>> type({}) == dict
True
>>> platform.__builtins__.__class__ == dict
True




>
> python stfu/testing/test_pyfactor.py
> Fcleaning stuff up
>
> ======================================================================
> 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'>"
>
> ----------------------------------------------------------------------
> Ran 1 test in 0.000s
>
> FAILED (failures=1)
>
> --
> John Maclean MSc. (DIC) Bsc. (Hons),Core Linux Systems Engineering,07739
> 171 531
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20100413/f31166e6/attachment.html>


More information about the Python-list mailing list