示例#1
0
            p = create_reader([254, 0xff])
            p.read_length_coded_binary()
            self.fail('expected underflow')
        except BufferUnderflowError:
            pass
        except:
            self.fail('expected underflow')

        try:
            p = create_reader([254, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff])
            p.read_length_coded_binary()
            self.fail('expected underflow')
        except BufferUnderflowError:
            pass
        except:
            self.fail('expected underflow')

        p = create_reader([254, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff])

        self.assertEquals(9, p.packet.limit)
        self.assertEquals(0, p.packet.position)
        self.assertEquals(0xFFFFFFFFFFFFFFFFL, p.read_length_coded_binary())
        self.assertEquals(9, p.packet.limit)
        self.assertEquals(9, p.packet.position)

if __name__ == '__main__':
    unittest.main(timeout = 60)



示例#2
0
            try:        
                list(cnn.perform(cnn.get('/hello/2')))
                self.fail('expected eof')
            except HTTPError, e:
            	pass
	    except:
                self.fail('expected http errror')       
        finally:
            cnn.close()

    def testHTTPPost(self):
        cnn = HTTPConnection()

        try:
            cnn.connect(('localhost', SERVER_PORT))
            for i in [1, 2, 4, 8, 16, 32, 100, 1000, 10000, 100000, 200000]:
                post_data = 'test post data' * i
                request = cnn.post('/post', post_data, host = 'testhost.nl')
                response = cnn.perform(request)
                self.assertEquals('ok', response.body)
                self.assertTrue('HTTP_CONTENT_LENGTH' in self.saver.environ)
                self.assertEquals(len(post_data), int(self.saver.environ['HTTP_CONTENT_LENGTH']))
                self.assertEquals(post_data, self.saver.body)
                self.assertEquals('testhost.nl', self.saver.environ['HTTP_HOST'])
        finally:
            cnn.close()        
        
if __name__ == '__main__':
    unittest.main(timeout = 100.0)

示例#3
0
    def testWebJSON(self):

        cnn = None
        try:
            cnn = HTTPConnection()
            cnn.connect(('localhost', 9090))
            response = cnn.perform(cnn.get('/json'))
            status = response.status
            self.assertEquals('HTTP/1.1 200 OK', status)
            self.assertEquals('application/json; charset=UTF-8',
                              response.get_header('Content-Type'))
            self.assertEquals('9', response.get_header('Content-Length'))
            self.assertEquals("[1,2,3,4]", response.body)
        finally:
            if cnn: cnn.close()

    def testMany(self):
        cnn = None
        try:
            cnn = HTTPConnection()
            cnn.connect(('localhost', 9090))
            response = cnn.perform(cnn.get('/many'))
            self.assertEquals('blaat' * 10, response.body)
        finally:
            if cnn: cnn.close()


if __name__ == '__main__':
    unittest.main(timeout=100)
示例#4
0
        pool.disconnect(cnn2)
        #cnn2 should be closed on old age

        self.assertFalse(cnn1.is_connected())
        self.assertFalse(cnn2.is_connected())

    def testNullPool(self):

        pool = NullPool(client, DB_ARGS)

        new1, cnn1 = pool.connect()
        new2, cnn2 = pool.connect()

        self.assertTrue(new1)
        self.assertTrue(new2)

        self.assertTrue(cnn1.is_connected())
        self.assertTrue(cnn2.is_connected())

        pool.disconnect(cnn1, True)
        pool.disconnect(cnn2, False)

        #null pool always disconnects
        self.assertFalse(cnn1.is_connected())
        self.assertFalse(cnn2.is_connected())


if __name__ == '__main__':
    unittest.main(timeout=60)
示例#5
0
from concurrence import unittest, Tasklet

class TestTest(unittest.TestCase):
    def testTimeout(self):
        try:
            Tasklet.sleep(4)
            self.fail('expected timeout!')
        except TaskletExit:
            pass #caused by timeout
        
if __name__ == '__main__':
    unittest.main(timeout = 2)
示例#6
0
        
        for i in range(10):
            with timer.time():
                Tasklet.sleep(0.1)

        self.assertEquals(10, timer.count)
        self.assertAlmostEqual(0.1, timer.avg, places = 1)
        
        timer = StatisticExtra(g = 0.1) #low g for fast convergence
        for i in range(11):
            with timer.time():
                Tasklet.sleep(0.2)

        self.assertEquals(11, timer.count)
        self.assertAlmostEqual(0.2, timer.avg, places = 1)
        
        
    def testStatistic(self):
        
        stat = Statistic(0)
        
        self.assertEquals(0, stat.count)
        stat += 1
        self.assertEquals(1, stat.count)
        stat -= 1
        self.assertEquals(0, stat.count)
        
if __name__ == '__main__':
    unittest.main()
    
示例#7
0
                client_results.append(MSG_SUM.call(remote_task)(10, 20, 30))
                client_results.append(MSG_SUM.call(remote_task)(10, 20, 30))
                MSG_TEST.send(remote_task)(20, 30)
                MSG_TEST.send(remote_task)(30, 40)

                MSG_SLEEP.call(remote_task)(1)

                try:
                    MSG_SLEEP.call(remote_task, timeout = 1)(2)
                    self.fail("expected timeout")
                except TimeoutError:
                    pass #expected

                MSG_QUIT.send(remote_task)()
                Tasklet.sleep(2)
                remote_client.close()
            except Exception:
                logging.exception("")
                self.fail("")

        server_task = Tasklet.new(server)()
        client_task = Tasklet.new(client)()

        Tasklet.join_children()

        self.assertEquals([60,60], client_results)
        self.assertEquals(['t', 't', 's', 's', 't', 't', 'sl', 'sl', 'q'], server_results)

if __name__ == '__main__':
    unittest.main(timeout = 5)
示例#8
0
            pass

    def testTaskInstance2(self):

        AdderInstance = TaskInstance(True)

        with AdderInstance.set(Adder(10)):

            self.assertEquals(30, AdderInstance.sum(20))

            #now start 2 child tasks
            def t():
                self.assertEquals(
                    30,
                    AdderInstance.sum(20))  #expect to find parents instance
                #now set my own instance
                with AdderInstance.set(Adder(20)):
                    self.assertEquals(40, AdderInstance.sum(20))
                #now it must be unset, and we will find parents instance instead
                self.assertEquals(30, AdderInstance.sum(20))

            t1 = Tasklet.new(t)()
            t2 = Tasklet.new(t)()
            Tasklet.join_all([t1, t2])

            self.assertEquals(30, AdderInstance.sum(20))


if __name__ == '__main__':
    unittest.main()
示例#9
0
from concurrence import unittest, Tasklet
import os


class TestTest(unittest.TestCase):
    def testTimeout(self):
        try:
            Tasklet.sleep(4)
            self.fail('expected timeout!')
        except TaskletExit:
            pass  #caused by timeout


def ontimeout():
    os._exit(0)


if __name__ == '__main__':
    unittest.main(timeout=2, ontimeout=ontimeout)
示例#10
0
from concurrence import unittest, Tasklet
import os

class TestTest(unittest.TestCase):
    def testTimeout(self):
        try:
            Tasklet.sleep(4)
            self.fail('expected timeout!')
        except TaskletExit:
            pass #caused by timeout

def ontimeout():
    os._exit(0)

if __name__ == '__main__':
    unittest.main(timeout = 2, ontimeout = ontimeout)
示例#11
0
                MSG_SLEEP.call(remote_task)(1)

                try:
                    MSG_SLEEP.call(remote_task, timeout = 1)(2)
                    self.fail("expected timeout")
                except TimeoutError:
                    pass #expected

                MSG_QUIT.send(remote_task)()
                Tasklet.sleep(2)
                remote_client.close()
            except Exception:
                logging.exception("")
                self.fail("")
        
        server_task = Tasklet.new(server)()
        client_task = Tasklet.new(client)()

        Tasklet.join_children()
        
        self.assertEquals([60,60], client_results)
        self.assertEquals(['t', 't', 's', 's', 't', 't', 'sl', 'sl', 'q'], server_results)




        
if __name__ == '__main__':
    unittest.main(timeout = 5)