<br><br><div class="gmail_quote">On Tue, Apr 13, 2010 at 10:01 AM, John Maclean <span dir="ltr"><<a href="mailto:jayeola@gmail.com">jayeola@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
I normally use  languages unit testing framework to get a better<br>
understanding of how a language works. Right now I want to grok the<br>
platform module;<br>
<br>
<br>
 1 #!/usr/bin/env python<br>
  2 '''a pythonic factor'''<br>
  3 import unittest<br>
  4 import platform<br>
  5<br>
  6 class TestPyfactorTestCase(unittest.TestCase):<br>
  7     def setUp(self):<br>
  8         '''setting up stuff'''<br>
 13<br>
 14     def testplatformbuiltins(self): 15<br>
'''platform.__builtins__.blah '''<br>
 16         self.assertEquals(platform.__builtins__.__class__, "<type 'd<br>
    ict'>")<br>
 17<br>
 18<br>
 19     def tearDown(self):<br>
 20         print 'cleaning stuff up'<br>
 21<br>
 22 if __name__ == "__main__":<br>
 23     unittest.main()<br>
<br>
<br>
Is there an error in my syntax? Why is my test failing? Line 16.<br>
<br></blockquote><div><br>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.<br>
<br>>>> type({}) == "<type 'dict'>"<br>False<br>>>> type({})<br><type 'dict'><br>>>> str(type({})) == "<type 'dict'>"<br>True<br>>>> type({}) == dict<br>
True<br>>>> platform.__builtins__.__class__ == dict<br>True<br><br><br> </div><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<br>
python stfu/testing/test_pyfactor.py<br>
Fcleaning stuff up<br>
<br>
======================================================================<br>
FAIL: platform.__builtins__.blah<br>
----------------------------------------------------------------------<br>
Traceback (most recent call last):<br>
  File "stfu/testing/test_pyfactor.py", line 16, in testplatformbuiltins<br>
    self.assertEquals(platform.__builtins__.__class__, "<type 'dict'>")<br>
AssertionError: <type 'dict'> != "<type 'dict'>"<br>
<br>
----------------------------------------------------------------------<br>
Ran 1 test in 0.000s<br>
<br>
FAILED (failures=1)<br>
<br>
--<br>
John Maclean MSc. (DIC) Bsc. (Hons),Core Linux Systems Engineering,07739<br>
171 531<br>
<font color="#888888">--<br>
<a href="http://mail.python.org/mailman/listinfo/python-list" target="_blank">http://mail.python.org/mailman/listinfo/python-list</a><br>
</font></blockquote></div><br>