Commits

Ronald Oussoren  committed 3fff9b2

* Add svn:ignore property to the examples and to the project root. In both
cases to avoid messages about 'dist' and 'build' in svn status.
* Move AppKit/test_bitmap.py to AppKit/test/
* Surpress messages to stderr in the unittests, anything that is printed during
'python setup.py test' is now cause for concern :-)

  • Participants
  • Parent commits 44b45af
  • Branches pyobjc-ancient

Comments (0)

Files changed (5)

File Lib/AppKit/test/test_nsbitmap.py

+import unittest
+import AppKit
+
+class TestNSBitmapImageRep (unittest.TestCase):
+
+    def test_getTIFFCompressionTypes(self):
+        r = AppKit.NSBitmapImageRep.getTIFFCompressionTypes_count_()
+
+        self.assert_(isinstance(r, tuple))
+        self.assertEquals(len(r), 2)
+
+        lst, ln = r
+
+        self.assert_(isinstance(lst, tuple))
+        self.assert_(isinstance(ln, int))
+
+        self.assertEquals(len(lst), ln)
+        self.assert_(reduce(lambda x, y: x and isinstance(x, int), lst, True))
+
+if __name__ == "__main__":
+    unittest.main()

File Lib/AppKit/test/test_nsbitmapimagerep.py

         self.assertEquals(bitmapData, singlePlane)
 
 class TestBadCreation(unittest.TestCase):
+
+    # Redirect stderr to /dev/null for the duration of this test, 
+    # NSBitmapImageRep will write an error message to stderr.
+
+    def setUp(self):
+        import os
+        self.duppedStderr = os.dup(2)
+        fp = os.open('/dev/null', os.O_RDWR)
+        os.dup2(fp, 2)
+        os.close(fp)
+
+    def tearDown(self):
+        import os
+        os.dup2(self.duppedStderr, 2)
+
+
+
     def test_AllocInit(self):
         y = NSBitmapImageRep.alloc()
         try:

File Lib/AppKit/test_nsbitmap.py

-import unittest
-import AppKit
-
-class TestNSBitmapImageRep (unittest.TestCase):
-
-    def test_getTIFFCompressionTypes(self):
-        r = AppKit.NSBitmapImageRep.getTIFFCompressionTypes_count_()
-
-        self.assert_(isinstance(r, tuple))
-        self.assertEquals(len(r), 2)
-
-        lst, ln = r
-
-        self.assert_(isinstance(lst, tuple))
-        self.assert_(isinstance(ln, int))
-
-        self.assertEquals(len(lst), ln)
-        self.assert_(reduce(lambda x, y: x and isinstance(x, int), lst, True))
-
-if __name__ == "__main__":
-    unittest.main()

File Lib/Foundation/test/test_threading.py

         self.assertEquals(lst, range(100))
 
     def testPyObject(self):
+        import os
 
         class TestThreadRunner :
             def run_(self, argument):
         myObj = TestThreadRunner()
         lst = []
 
-        NSThread.detachNewThreadSelector_toTarget_withObject_(
+        # Redirect stderr to avoid spurious messages when running the
+        # tests.
+        dupped = os.dup(2)
+        fp = os.open('/dev/null', os.O_RDWR)
+        os.dup2(fp, 2)
+        os.close(fp)
+
+        try:
+            NSThread.detachNewThreadSelector_toTarget_withObject_(
                 'run:', myObj, lst)
 
-        lst2 = []
-        for i in range(100):
-            lst2.append(i*2)
+            lst2 = []
+            for i in range(100):
+                lst2.append(i*2)
 
-        time.sleep(2)
-        self.assertEquals(lst, range(100))
+            time.sleep(2)
+            self.assertEquals(lst, range(100))
+
+        finally:
+            os.dup2(dupped, 2)
 
     def testCalling(self):
         class Dummy:

File Lib/objc/test/test_regr.py

         from Foundation import NSLog, NSAutoreleasePool, NSObject
         import AppKit
         from threading import Thread
+        import os
 
-        class ThreadHangObject(NSObject):
-            def init(self):
-                self.t = MyThread()
-                self.t.start()
-                return self
+        # Temporarily redirect stderr to a file, this allows us to check
+        # that NSLog actually wrote some text.
+        fp = os.open('/tmp/pyobjc-thread.txt', os.O_RDWR|os.O_CREAT, 0666)
+        dupped = os.dup(2)
+        os.dup2(fp, 2)
 
-        aList = []
-        class MyThread(Thread):
-            def run(self):
-                pool = NSAutoreleasePool.alloc().init()
-                aList.append("before")
-                NSLog("does this print?")
-                aList.append("after")
+        try:
 
-        o = ThreadHangObject.alloc().init()
-        o.t.join()
+            class ThreadHangObject(NSObject):
+                def init(self):
+                    self.t = MyThread()
+                    self.t.start()
+                    return self
 
-        self.assertEquals(aList, ["before", "after"])
+            aList = []
+            class MyThread(Thread):
+                def run(self):
+                    pool = NSAutoreleasePool.alloc().init()
+                    aList.append("before")
+                    NSLog("does this print?")
+                    aList.append("after")
+
+            o = ThreadHangObject.alloc().init()
+            o.t.join()
+
+            self.assertEquals(aList, ["before", "after"])
+
+        finally:
+            os.close(fp)
+            os.dup2(dupped, 2)
+
+        data = open('/tmp/pyobjc-thread.txt', 'r').read()
+        self.assert_('does this print?' in data)
+
 
 if __name__ == '__main__':
     unittest.main()