Ejemplo n.º 1
0
	def test_heartbeat(self):
		frame = Frame(Frame.HEARTBEAT_TYPE, 0)
		expected = (
			"\x04" # frame type: body
			"\x00\x00" # channel: 0
			"\x00\x00\x00\x00" # payload size: 0
			"\xCE" # frame end
		)
		self.assertEquals(frame.pack(), expected)
Ejemplo n.º 2
0
	def test_body_frame(self):
		frame = Frame(Frame.BODY_TYPE, 1, "placeholder strings are hard")
		expected = (
			"\x03" # frame type: body
			"\x00\x01" # channel: 1
			"\x00\x00\x00\x1c" # payload size: 28
			# payload:
				"placeholder strings are hard"
			"\xCE" # frame end
		)
		self.assertEquals(frame.pack(), expected)
Ejemplo n.º 3
0
	def test_header_frame(self):
		frame = Frame(Frame.HEADER_TYPE, 1, TEST_METHOD_CLASS, 42, {"an_int": 7, "a_bool": True})
		expected = (
			"\x02" # frame type: header
			"\x00\x01" # channel: 1
			"\x00\x00\x00\x10" # payload size: 16
			# payload:
				"\xff\x42" # method class: 0xff42
				"\x00\x00" # weight: 0
				"\x00\x00\x00\x00\x00\x00\x00\x2a" # content body size: 42 (meaningless here)
				# properties:
					"\xc0\x00" # flags: 1st and 2nd bits set, no more flags
					"\x00\x07" # an_int: 7
					# a_bool: present, but no data as it is a bool
			"\xCE" # frame end
		)
		self.assertEquals(frame.pack(), expected)
Ejemplo n.º 4
0
	def check(self, frame, expected):
		self.assertEquals(frame.pack(), expected)
		unpacked, leftover = Frame.unpack(expected)
		self.assertEquals(unpacked, frame)
		self.assertEquals(leftover, '')