Beispiel #1
0
 def test_dispose_all(self):
     v1 = twistit.extract(self.target.acquire())
     v2 = twistit.extract(self.target.acquire())
     self.target.release(v1)
     self.target.release(v2)
     self.target.dispose_all()
     self.assertEqual({v1,v2}, self.disposed)
Beispiel #2
0
 def test_two_frames(self):
     self.target.write(self.header.pack(10, 4))
     self.target.write("abcd")
     self.target.write(self.header.pack(20, 4))
     self.target.write("1234")
     
     fid, blob = twistit.extract(self.target.next_frame())
     self.assertEqual(10, fid)
     self.assertEqual("abcd", twistit.extract(blob.read_all()))
     
     fid, blob = twistit.extract(self.target.next_frame())
     self.assertEqual(20, fid)
     self.assertEqual("1234", twistit.extract(blob.read_all()))
Beispiel #3
0
 def test_blob(self):
     expected = Msg("hello", None)
     
     pickleout = pickle.dumps(expected, pickle.HIGHEST_PROTOCOL)
     header = rpc.HEADER.pack(len(pickleout), 6)
     data = header + pickleout + "World!"
     
     src = blob.StringBlob(data)
     
     d = rpc.deserialize(src)
     actual = twistit.extract(d)
     
     payload = twistit.extract(actual.blob.read_all())
     
     self.assertEqual(expected, actual)
     self.assertEqual("World!", payload)
Beispiel #4
0
 def test_read_all(self):
     self.target._size = 6
     self.target.write("abc")
     d = self.target.read_all()
     self.target.write("123")
     self.target.done()
     actual = twistit.extract(d)
     self.assertEqual("abc123", actual)
Beispiel #5
0
 def test_noblob(self):
     msg = Msg("hello", None)
     actual = rpc.serialize(msg)
     actual = actual.read_all()
     actual = twistit.extract(actual)
     
     pickleout = pickle.dumps(msg, pickle.HIGHEST_PROTOCOL)
     header = rpc.HEADER.pack(len(pickleout), 0)
     expected = header + pickleout
     self.assertEqual(expected, actual)
Beispiel #6
0
 def test_blob(self):
     msg = Msg("hello", blob.StringBlob("world"))
     actual = rpc.serialize(msg)
     actual = actual.read_all()
     actual = twistit.extract(actual)
     
     pickleout = pickle.dumps(msg, pickle.HIGHEST_PROTOCOL)
     header = rpc.HEADER.pack(len(pickleout), 5)
     expected = header + pickleout + "world"
     self.assertEqual(expected, actual)
Beispiel #7
0
 def test_concat_string_blob(self):
     target = blob.PassthroughBlob(11, "target")
     d = target.read_all()
     target.write("hello")
     b = blob.PassthroughBlob(6, "b")
     b.write_to(target)
     b.write("abc")
     b.write("def")
     b.done()
     target.done()
     
     actual = twistit.extract(d)
     self.assertEqual("helloabcdef", actual)
Beispiel #8
0
 def test_noblob(self):
     expected = Msg("hello", None)
     
     pickleout = pickle.dumps(expected, pickle.HIGHEST_PROTOCOL)
     header = rpc.HEADER.pack(len(pickleout), 0)
     data = header + pickleout
     
     src = blob.StringBlob(data)
     
     d = rpc.deserialize(src)
     actual = twistit.extract(d)
     
     self.assertEqual(expected, actual)
Beispiel #9
0
 def test_blob_stream(self):
     expected = Msg("hello", None)
     
     pickleout = pickle.dumps(expected, pickle.HIGHEST_PROTOCOL)
     header = rpc.HEADER.pack(len(pickleout), 6)
     data = header + pickleout
     
     src = blob.PassthroughBlob(len(data)+6)
     d = rpc.deserialize(src)
     
     src.write(data)
     
     actual = twistit.extract(d)
     
     self.assertEqual(expected, actual)
     
     src.write("World!")
     src.done()
     
     payload = twistit.extract(actual.blob.read_all())
     
     self.assertEqual("World!", payload)
Beispiel #10
0
 def test_blob_stream(self):
     b = blob.PassthroughBlob(6)
     msg = Msg("hello", b)
     actual = rpc.serialize(msg)
     actual = actual.read_all()
     
     b.write("world!")
     b.done()
     
     actual = twistit.extract(actual)
     
     pickleout = pickle.dumps(msg, pickle.HIGHEST_PROTOCOL)
     header = rpc.HEADER.pack(len(pickleout), 6)
     expected = header + pickleout + "world!"
     self.assertEqual(expected, actual)
Beispiel #11
0
 def test_empty_frame(self):
     self.target.write(self.header.pack(10, 0))
     fid, blob = twistit.extract(self.target.next_frame())
     self.assertEqual(10, fid)
     self.assertEqual("", twistit.extract(blob.read_all()))
Beispiel #12
0
 def test_defer_callsback(self):
     self.target._size = 3
     self.target.write("abc")
     d = self.target.write_to(self.consumer)
     self.target.done()
     twistit.extract(d)
Beispiel #13
0
 def test_data(self):
     target = blob.StringListBlob(["Hello", " ", "World", "!"])
     actual = twistit.extract(target.read_all())
     self.assertEqual("Hello World!", actual)
Beispiel #14
0
 def test_success(self):
     d = defer.succeed(42)
     self.assertEqual(42, twistit.extract(d))
Beispiel #15
0
 def test_dispose(self):
     twistit.extract(self.target.acquire('a'))
     v2 = twistit.extract(self.target.acquire('a'))
     twistit.extract(self.target.acquire('a'))
     self.target.dispose(v2)
     self.assertEqual({v2}, self.disposed)
Beispiel #16
0
 def test_dont_share(self):
     v1 = twistit.extract(self.target.acquire('a'))
     self.target.release(v1)
     self.assertEqual(('b',1), twistit.extract(self.target.acquire('b')))
Beispiel #17
0
 def test_acquire_differentkeys(self):
     self.assertEqual(('a',0), twistit.extract(self.target.acquire('a')))
     self.assertEqual(('b',1), twistit.extract(self.target.acquire('b')))
Beispiel #18
0
 def test_dispose(self):
     v1 = twistit.extract(self.target.acquire())
     self.target.dispose(v1)
     v2 = twistit.extract(self.target.acquire())
     self.assertEqual(1, v2)
     self.assertEqual({0}, self.disposed)
Beispiel #19
0
 def test_release(self):
     v = twistit.extract(self.target.acquire())
     self.target.release(v)
Beispiel #20
0
 def test_acquire_two(self):
     self.assertEqual(0, twistit.extract(self.target.acquire()))
     self.assertEqual(1, twistit.extract(self.target.acquire()))
Beispiel #21
0
 def test_large(self):
     self.target.write(self.header.pack(10, 8))
     self.target.write("abcd")
     self.target.write("1234")
     _, blob = twistit.extract(self.target.next_frame())
     self.assertEqual("abcd1234", twistit.extract(blob.read_all()))
Beispiel #22
0
 def test_acquire(self):
     self.assertEqual(('a',0), twistit.extract(self.target.acquire('a')))
Beispiel #23
0
 def test_a_r_a(self):
     v = twistit.extract(self.target.acquire('a'))
     self.target.release(v)
     w = twistit.extract(self.target.acquire('a'))
     self.assertEqual(v, w)