Ejemplo n.º 1
0
    def test01_missingConfigFileGivenOnCLI_forceReactorInstall(self):
        import platform
        from twisted.internet import epollreactor

        does_not_exist_file = os.path.join(self.tmpdir, "thisdoesnotexist.xml")

        # Fake system
        _s = None
        if platform.system() == 'Windows':
            _s, platform.system = platform.system, lambda: "NotWindowsButReallyIs"

        # Fake reactor
        reactor_called = [False]
        def reactorFake(): reactor_called[0] = True
        _ri, epollreactor.install = epollreactor.install, reactorFake

        #
        _r = sys.modules['twisted.internet.reactor']
        del sys.modules['twisted.internet.reactor']


        try:
            pokerServerRun([doesNotExistFile])
            self.fail("previous line should have thrown exception")
        except:
            pass
        finally:
            epollreactor.install = _ri
            sys.modules['twisted.internet.reactor'] = _r
            if _s:
                platform.system = _s
        return
    def test01_validConfig_mockupStartApplication(self):
        """test01_validConfig_mockupStartApplication
        Test that the pokerserver application runs properly.  Since the
        reactor.run() is called by pokerserver's run(), this test might
        HANG INDEFINITELY for some types of test failures.  Unlikely but
        possible."""
        from pokernetwork.pokerserver import run as pokerServerRun

        from twisted.application import app
        configFile = os.path.join(self.tmpdir, "ourconfig.xml")
        configFH = open(configFile, "w")
        configFH.write(settings_xml_server_open_options %\
                       { 'listen_options' : '',
                        'additional_path' : self.tmpdir,
                        'script_dir': SCRIPT_DIR})
        self.setArgv([configFile])
        configFH.close()

        def mockStartApplication(application, val):
            from twisted.python.components import Componentized
            self.failUnless(isinstance(application, Componentized))
            self.assertEquals(val, None)
        savedStartApplication = app.startApplication
        app.startApplication = mockStartApplication

        def doCallback(val):
            self.assertEquals(val, "done")
            app.startApplication = savedStartApplication
            reactor.stop()

        defferedStillRunningMeansReactorNotStarted = defer.Deferred()
        defferedStillRunningMeansReactorNotStarted.addCallback(doCallback)

        reactor.callLater(1, lambda: defferedStillRunningMeansReactorNotStarted.callback("done"))
        pokerServerRun()
Ejemplo n.º 3
0
    def test01_missingConfigFileGivenOnCLI_forceReactorInstall(self):
        import platform
        from twisted.internet import epollreactor

        does_not_exist_file = os.path.join(self.tmpdir, "thisdoesnotexist.xml")

        # Fake system
        _s = None
        if platform.system() == 'Windows':
            _s, platform.system = platform.system, lambda: "NotWindowsButReallyIs"

        # Fake reactor
        reactor_called = [False]

        def reactorFake():
            reactor_called[0] = True

        _ri, epollreactor.install = epollreactor.install, reactorFake

        #
        _r = sys.modules['twisted.internet.reactor']
        del sys.modules['twisted.internet.reactor']

        try:
            pokerServerRun([doesNotExistFile])
            self.fail("previous line should have thrown exception")
        except:
            pass
        finally:
            epollreactor.install = _ri
            sys.modules['twisted.internet.reactor'] = _r
            if _s:
                platform.system = _s
        return
Ejemplo n.º 4
0
 def test00_missingConfigFileGivenOnCLI(self):
     does_not_exist_file = os.path.join(self.tmpdir, "thisdoesnotexist.xml")
     try:
         pokerServerRun([doesNotExistFile])
         self.fail("previous line should have thrown exception")
     except:
         pass
Ejemplo n.º 5
0
 def test00_missingConfigFileGivenOnCLI(self):
     does_not_exist_file = os.path.join(self.tmpdir, "thisdoesnotexist.xml")
     try:
         pokerServerRun([doesNotExistFile])
         self.fail("previous line should have thrown exception")
     except:
         pass
Ejemplo n.º 6
0
    def test01_missingConfigFileGivenOnCLI_forceReactorInstall(self):
        import platform
        from twisted.internet import pollreactor
        doesNotExistFile = os.path.join(self.tmpdir, "thisdoesnotexist.xml")
        caughtIt = False

        saveSystem = platform.system
        if platform.system() == "Windows":
            def fakeSystem():
                return "NotWindowsButReallyIs"
            platform.system = fakeSystem

        reactorCalled = False
        def reactorFake():
            reactorCalled = True
        saveReactor = pollreactor.install
        pollreactor.install = reactorFake

        reactorModulesSave = sys.modules['twisted.internet.reactor']
        del sys.modules['twisted.internet.reactor']

        try:
            pokerServerRun()
            self.fail("previous line should have thrown exception")
        except exceptions.SystemExit, e:
            self.assertEquals(e.__str__(), "1")
            caughtIt = True
Ejemplo n.º 7
0
    def test01_missingConfigFileGivenOnCLI_forceReactorInstall(self):
        import platform
        from twisted.internet import pollreactor
        doesNotExistFile = os.path.join(self.tmpdir, "thisdoesnotexist.xml")
        caughtIt = False

        saveSystem = platform.system
        if platform.system() == "Windows":

            def fakeSystem():
                return "NotWindowsButReallyIs"

            platform.system = fakeSystem

        reactorCalled = False

        def reactorFake():
            reactorCalled = True

        saveReactor = pollreactor.install
        pollreactor.install = reactorFake

        reactorModulesSave = sys.modules['twisted.internet.reactor']
        del sys.modules['twisted.internet.reactor']

        try:
            pokerServerRun()
            self.fail("previous line should have thrown exception")
        except exceptions.SystemExit, e:
            self.assertEquals(e.__str__(), "1")
            caughtIt = True
Ejemplo n.º 8
0
 def test00_missingConfigFileGivenOnCLI(self):
     doesNotExistFile = os.path.join(self.tmpdir, "thisdoesnotexist.xml")
     caughtIt = False
     try:
         sys.argv = [ doesNotExistFile ]
         pokerServerRun()
         self.fail("previous line should have thrown exception")
     except exceptions.SystemExit, e:
         self.assertEquals(e.__str__(), "1")
         caughtIt = True
Ejemplo n.º 9
0
 def test00_missingConfigFileGivenOnCLI(self):
     doesNotExistFile = os.path.join(self.tmpdir, "thisdoesnotexist.xml")
     caughtIt = False
     try:
         sys.argv = [doesNotExistFile]
         pokerServerRun()
         self.fail("previous line should have thrown exception")
     except exceptions.SystemExit, e:
         self.assertEquals(e.__str__(), "1")
         caughtIt = True