def stubout_urlopen(url):
    if "bogus" in url:
        raise HTTPError(url, "404", "No such resource", "", None)

    elif "localhost" in url:
        return StringIO(unicode_str("This is a test file.\n"))

    else:
        raise ValueError("Unexpected URL %r in stubout_urlopen" % url)
Example #2
0
def stubout_urlopen(url):
    if 'bogus' in url:
        raise HTTPError(url, '404', 'No such resource', '', None)

    elif 'localhost' in url:
        return StringIO(unicode_str('This is a test file.\n'))

    else:
        raise ValueError('Unexpected URL %r in stubout_urlopen' % url)
 def _task_changed(self, task):
     """ Name the action (unless a name has already been assigned).
     """
     if task and not self.name:
         name = unicode_str()
         for factory in task.window.application.task_factories:
             if factory.id == self.task_id:
                 name = factory.name
                 break
         self.name = name
Example #4
0
 def _task_changed(self, task):
     """ Name the action (unless a name has already been assigned).
     """
     if task and not self.name:
         name = unicode_str()
         for factory in task.window.application.task_factories:
             if factory.id == self.task_id:
                 name = factory.name
                 break
         self.name = name
Example #5
0
    def _get_title(self):
        """ If the application has a name, add it to the title. Otherwise,
            behave like the base class.
        """
        if self._title or self.active_task is None:
            return self._title

        title = self.active_task.name
        if self.application.name:
            form = unicode_str('%s - %s')
            title = form % (title, self.application.name)
        return title
Example #6
0
    def _get_title(self):
        """ If the application has a name, add it to the title. Otherwise,
            behave like the base class.
        """
        if self._title or self.active_task is None:
            return self._title

        title = self.active_task.name
        if self.application.name:
            form = unicode_str('%s - %s')
            title = form % (title, self.application.name)
        return title
 def _get_name(self):
     if self.window.active_task:
         return self.window.active_task.name
     return unicode_str()
Example #8
0
 def _get_name(self):
     if self.window.active_task:
         return self.window.active_task.name
     return unicode_str()
    def testCommunication(self):
        """ Can the Server communicate with Clients and handle errors
            appropriately?
        """
        # Test server set up

        # Does the ping operation work when the Server is not running?
        self.assert_(not Server.ping(get_server_port()))

        # Set up server thread
        serverThread = TestThread()
        serverThread.setDaemon(True)
        serverThread.start()
        sleep(.5)
        self.assert_(os.path.exists(LOCK_PATH))

        # Test normal operation
        tmp = get_server_port()
        self.assert_(Server.ping(tmp))

        client1 = TestClient(self_type='client1', other_type='client2')
        client1.register()
        client2 = TestClient(self_type='client2', other_type='client1')
        client2.register()
        sleep(.5)
        self.assert_(not(client1.orphaned or client2.orphaned))

        client1.send_command("foo", "bar")
        sleep(.1)
        self.assertEqual(client2.command, "foo")
        self.assertEqual(client2.arguments, "bar")

        client1.send_command(unicode_str("Très"), "bien")
        sleep(.1)
        self.assertEqual(client2.command, unicode_str("Très"))
        self.assertEqual(client2.arguments, "bien")


        client1.unregister()
        sleep(.1)
        self.assert_(client1.orphaned and client2.orphaned)

        client1.register()
        sleep(.1)
        self.assert_(not(client1.orphaned or client2.orphaned))

        # Simulated breakage -- does the Server handle unexpected communication
        # failure?

        # Have client1 'die'. We send the dummy command to force its connection
        # loop to terminate after the call to 'stop'. (In Python we can't just
        # kill the thread, which is really what we want to do in this case.)
        client1._communication_thread.stop()
        sleep(.1)
        serverThread.server._send_to(client1._port, "dummy", "")
        sleep(.1)

        # The Server should inform client1 that it could not complete its
        # request
        client2.send_command("foo", "bar")
        sleep(.1)
        self.assert_(client2.orphaned)
        self.assertEqual(client2.error_count, 1)
    def testCommunication(self):
        """ Can the Server communicate with Clients and handle errors
            appropriately?
        """
        # Test server set up

        # Does the ping operation work when the Server is not running?
        self.assert_(not Server.ping(get_server_port()))

        # Set up server thread
        serverThread = TestThread()
        serverThread.setDaemon(True)
        serverThread.start()
        sleep(.5)
        self.assert_(os.path.exists(LOCK_PATH))

        # Test normal operation
        tmp = get_server_port()
        self.assert_(Server.ping(tmp))

        client1 = TestClient(self_type='client1', other_type='client2')
        client1.register()
        client2 = TestClient(self_type='client2', other_type='client1')
        client2.register()
        sleep(.5)
        self.assert_(not (client1.orphaned or client2.orphaned))

        client1.send_command("foo", "bar")
        sleep(.1)
        self.assertEqual(client2.command, "foo")
        self.assertEqual(client2.arguments, "bar")

        client1.send_command(unicode_str("Très"), "bien")
        sleep(.1)
        self.assertEqual(client2.command, unicode_str("Très"))
        self.assertEqual(client2.arguments, "bien")

        client1.unregister()
        sleep(.1)
        self.assert_(client1.orphaned and client2.orphaned)

        client1.register()
        sleep(.1)
        self.assert_(not (client1.orphaned or client2.orphaned))

        # Simulated breakage -- does the Server handle unexpected communication
        # failure?

        # Have client1 'die'. We send the dummy command to force its connection
        # loop to terminate after the call to 'stop'. (In Python we can't just
        # kill the thread, which is really what we want to do in this case.)
        client1._communication_thread.stop()
        sleep(.1)
        serverThread.server._send_to(client1._port, "dummy", "")
        sleep(.1)

        # The Server should inform client1 that it could not complete its
        # request
        client2.send_command("foo", "bar")
        sleep(.1)
        self.assert_(client2.orphaned)
        self.assertEqual(client2.error_count, 1)