Ticket #3707: patch 3707.diff

File patch 3707.diff, 10.1 KB (added by christianmlong, 12 years ago)

Added some skips for cases when we are on windows, but pywin32 is not available

  • twisted/internet/test/test_process.py

     
    2020from twisted.internet.error import ProcessDone, PotentialZombieWarning
    2121from twisted.internet.error import ProcessTerminated
    2222
     23skipWindowsNopywin32 = None
     24if platform.isWindows():
     25    try:
     26        import win32process
     27    except ImportError:
     28        skipWindowsNopywin32 = ("On windows, spawnProcess is not available "
     29                                "in the absence of win32process.")
    2330
    2431class _ShutdownCallbackProcessProtocol(ProcessProtocol):
    2532    """
     
    340347        self.runReactor(reactor)
    341348
    342349
     350ProcessTestsBuilder.skip = skipWindowsNopywin32
    343351globals().update(ProcessTestsBuilder.makeTestCaseClasses())
    344352
    345353
  • twisted/python/lockfile.py

     
    2525    _windows = False
    2626except:
    2727    _windows = True
    28     from win32api import OpenProcess
    29     import pywintypes
    3028
    31     ERROR_ACCESS_DENIED = 5
    32     ERROR_INVALID_PARAMETER = 87
     29    try:
     30        from win32api import OpenProcess
     31        import pywintypes
     32    except ImportError:
     33        kill = None
     34    else:
     35        ERROR_ACCESS_DENIED = 5
     36        ERROR_INVALID_PARAMETER = 87
    3337
     38        def kill(pid, signal):
     39            try:
     40                OpenProcess(0, 0, pid)
     41            except pywintypes.error, e:
     42                if e.args[0] == ERROR_ACCESS_DENIED:
     43                    return
     44                elif e.args[0] == ERROR_INVALID_PARAMETER:
     45                    raise OSError(errno.ESRCH, None)
     46                raise
     47            else:
     48                raise RuntimeError("OpenProcess is required to fail.")
     49
    3450    _open = file
    3551
    36     def kill(pid, signal):
    37         try:
    38             OpenProcess(0, 0, pid)
    39         except pywintypes.error, e:
    40             if e.args[0] == ERROR_ACCESS_DENIED:
    41                 return
    42             elif e.args[0] == ERROR_INVALID_PARAMETER:
    43                 raise OSError(errno.ESRCH, None)
    44             raise
    45         else:
    46             raise RuntimeError("OpenProcess is required to fail.")
    47 
    4852    # XXX Implement an atomic thingamajig for win32
    4953    def symlink(value, filename):
    5054        newlinkname = filename+"."+unique()+'.newlink'
     
    144148                            return False
    145149                        raise
    146150                    try:
    147                         kill(int(pid), 0)
     151                        if kill is not None:
     152                            kill(int(pid), 0)
    148153                    except OSError, e:
    149154                        if e.errno == errno.ESRCH:
    150155                            # The owner has vanished, try to claim it in the next
  • twisted/test/test_application.py

     
    1414from twisted.persisted import sob
    1515from twisted.python import usage
    1616from twisted.python.util import sibpath
     17from twisted.python.runtime import platform
    1718from twisted.internet import interfaces, defer
    1819from twisted.protocols import wire, basic
    1920from twisted.internet import protocol, reactor
     
    2324oldAppSuppressions = [util.suppress(message='twisted.internet.app is deprecated',
    2425                                    category=DeprecationWarning)]
    2526
     27skipWindowsNopywin32 = None
     28if platform.isWindows():
     29    try:
     30        import win32process
     31    except ImportError:
     32        skipWindowsNopywin32 = ("On windows, spawnProcess is not available "
     33                                "in the absence of win32process.")
     34
    2635class Dummy:
    2736    processName=None
    2837
     
    869878            env=None)
    870879        result.addCallback(_checkOutput)
    871880        return result
     881    test_qtStub.skip = skipWindowsNopywin32
    872882
    873883
    874884
  • twisted/test/test_lockfile.py

     
    1212from twisted.python import lockfile
    1313from twisted.python.runtime import platform
    1414
     15skipKill = None
     16if platform.isWindows():
     17    try:
     18        from win32api import OpenProcess
     19        import pywintypes
     20    except ImportError:
     21        skipKill = ("On windows, lockfile.kill is not implemented in the "
     22                    "absence of win32api and/or pywintypes.")
     23
    1524class UtilTests(unittest.TestCase):
    1625    """
    1726    Tests for the helper functions used to implement L{FilesystemLock}.
     
    8594        process which exists and signal C{0}.
    8695        """
    8796        lockfile.kill(os.getpid(), 0)
     97    test_kill.skip = skipKill
    8898
    8999
    90100    def test_killESRCH(self):
     
    95105        # Hopefully there is no process with PID 2 ** 31 - 1
    96106        exc = self.assertRaises(OSError, lockfile.kill, 2 ** 31 - 1, 0)
    97107        self.assertEqual(exc.errno, errno.ESRCH)
     108    test_killESRCH.skip = skipKill
    98109
    99110
     111    def test_noKillCall(self):
     112        """
     113        Verify that when L{lockfile.kill} does end up as None (e.g. on Windows
     114        without pywin32), it doesn't end up being called and raising a
     115        L{TypeError}.
     116        """
     117        self.patch(lockfile, "kill", None)
     118        fl = lockfile.FilesystemLock(self.mktemp())
     119        fl.lock()
     120        self.assertFalse(fl.lock())
    100121
     122
     123
    101124class LockingTestCase(unittest.TestCase):
    102125    def _symlinkErrorTest(self, errno):
    103126        def fakeSymlink(source, dest):
  • twisted/test/test_shortcut.py

     
    66import os
    77if os.name == 'nt':
    88
    9     from twisted.python import shortcut
     9    skipWindowsNopywin32 = None
     10    try:
     11        from twisted.python import shortcut
     12    except ImportError:
     13        skipWindowsNopywin32 = ("On windows, twisted.python.shortcut is not "
     14                                "available in the absence of win32com.")
    1015    import os.path
    1116    import sys
    1217
     
    1823            self.assert_(os.path.exists(tempname))
    1924            sc=shortcut.open(tempname)
    2025            self.assert_(sc.GetPath(0)[0].endswith('test_shortcut.py'))
     26    ShortcutTest.skip = skipWindowsNopywin32
  • twisted/test/test_stdio.py

     
    55
    66from twisted.trial import unittest
    77from twisted.python import filepath
     8from twisted.python.runtime import platform
    89from twisted.internet import error, defer, protocol, reactor
    910
    1011
     
    1516# the end, the functionality works.
    1617UNIQUE_LAST_WRITE_STRING = 'xyz123abc Twisted is great!'
    1718
     19skipWindowsNopywin32 = None
     20if platform.isWindows():
     21    try:
     22        import win32process
     23    except ImportError:
     24        skipWindowsNopywin32 = ("On windows, spawnProcess is not available "
     25                                "in the absence of win32process.")
    1826
     27
    1928class StandardIOTestProcessProtocol(protocol.ProcessProtocol):
    2029    """
    2130    Test helper for collecting output from a child process and notifying
     
    120129            self.failIfIn(1, p.data)
    121130            reason.trap(error.ProcessDone)
    122131        return self._requireFailure(d, processEnded)
     132    test_loseConnection.skip = skipWindowsNopywin32
    123133
    124134
    125135    def test_lastWriteReceived(self):
     
    159169                    p.data,))
    160170            reason.trap(error.ProcessDone)
    161171        return self._requireFailure(p.onCompletion, processEnded)
     172    test_lastWriteReceived.skip = skipWindowsNopywin32
    162173
    163174
    164175    def test_hostAndPeer(self):
     
    176187            self.failUnless(peer)
    177188            reason.trap(error.ProcessDone)
    178189        return self._requireFailure(d, processEnded)
     190    test_hostAndPeer.skip = skipWindowsNopywin32
    179191
    180192
    181193    def test_write(self):
     
    192204            self.assertEquals(p.data[1], 'ok!')
    193205            reason.trap(error.ProcessDone)
    194206        return self._requireFailure(d, processEnded)
     207    test_write.skip = skipWindowsNopywin32
    195208
    196209
    197210    def test_writeSequence(self):
     
    208221            self.assertEquals(p.data[1], 'ok!')
    209222            reason.trap(error.ProcessDone)
    210223        return self._requireFailure(d, processEnded)
     224    test_writeSequence.skip = skipWindowsNopywin32
    211225
    212226
    213227    def _junkPath(self):
     
    245259            self.failIf(toWrite, "Connection lost with %d writes left to go." % (len(toWrite),))
    246260            reason.trap(error.ProcessDone)
    247261        return self._requireFailure(d, processEnded)
     262    test_producer.skip = skipWindowsNopywin32
    248263
    249264
    250265    def test_consumer(self):
     
    263278            self.assertEquals(p.data[1], file(junkPath).read())
    264279            reason.trap(error.ProcessDone)
    265280        return self._requireFailure(d, processEnded)
     281    test_consumer.skip = skipWindowsNopywin32
  • twisted/web2/test/test_cgi.py

     
    33from twisted.trial import unittest
    44from twisted.internet import reactor, interfaces, defer
    55from twisted.python import util
     6from twisted.python.runtime import platform
    67from twisted.web2 import twcgi, server, http, iweb
    78from twisted.web2 import stream
    89from twisted.web2.test.test_server import SimpleRequest
    910
     11skipWindowsNopywin32 = None
     12if platform.isWindows():
     13    try:
     14        import win32process
     15    except ImportError:
     16        skipWindowsNopywin32 = ("On windows, spawnProcess is not available "
     17                                "in the absence of win32process.")
     18
    1019DUMMY_CGI = '''
    1120print "Header: OK"
    1221print
     
    298307        d.addCallback(_secondRequest)
    299308
    300309        return d
     310    test_scriptsExecute.skip = skipWindowsNopywin32