summaryrefslogtreecommitdiffhomepage
path: root/tests/test_message.py
diff options
context:
space:
mode:
authorJeff Forcier <jeff@bitprophet.org>2014-09-05 10:39:00 -0700
committerJeff Forcier <jeff@bitprophet.org>2014-09-05 10:39:00 -0700
commit0e0460f85942e79c94b7db9d93abdf60bf1dbac4 (patch)
tree152b80b4a2822abcb85136f7fbc7f9263279eb14 /tests/test_message.py
parent683b3c22893be899d2fdbf1ada35e61fba8a3d70 (diff)
parenteb7da84bee49f6e7b568ee00fd5f3db0bb29f36a (diff)
Merge branch 'master' into 131-int
Diffstat (limited to 'tests/test_message.py')
-rw-r--r--tests/test_message.py79
1 files changed, 41 insertions, 38 deletions
diff --git a/tests/test_message.py b/tests/test_message.py
index 7bfd44df..f308c037 100644
--- a/tests/test_message.py
+++ b/tests/test_message.py
@@ -7,7 +7,7 @@
# Software Foundation; either version 2.1 of the License, or (at your option)
# any later version.
#
-# Paramiko is distrubuted in the hope that it will be useful, but WITHOUT ANY
+# Paramiko is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
# details.
@@ -22,14 +22,15 @@ Some unit tests for ssh protocol message blocks.
import unittest
from paramiko.message import Message
+from paramiko.common import byte_chr, zero_byte
class MessageTest (unittest.TestCase):
- __a = '\x00\x00\x00\x17\x07\x60\xe0\x90\x00\x00\x00\x01q\x00\x00\x00\x05hello\x00\x00\x03\xe8' + ('x' * 1000)
- __b = '\x01\x00\xf3\x00\x3f\x00\x00\x00\x10huey,dewey,louie'
- __c = '\x00\x00\x00\x00\x00\x00\x00\x05\x00\x00\xf5\xe4\xd3\xc2\xb1\x09\x00\x00\x00\x01\x11\x00\x00\x00\x07\x00\xf5\xe4\xd3\xc2\xb1\x09\x00\x00\x00\x06\x9a\x1b\x2c\x3d\x4e\xf7'
- __d = '\x00\x00\x00\x05\x00\x00\x00\x05\x11\x22\x33\x44\x55\x01\x00\x00\x00\x03cat\x00\x00\x00\x03a,b'
+ __a = b'\x00\x00\x00\x17\x07\x60\xe0\x90\x00\x00\x00\x01\x71\x00\x00\x00\x05\x68\x65\x6c\x6c\x6f\x00\x00\x03\xe8' + b'x' * 1000
+ __b = b'\x01\x00\xf3\x00\x3f\x00\x00\x00\x10\x68\x75\x65\x79\x2c\x64\x65\x77\x65\x79\x2c\x6c\x6f\x75\x69\x65'
+ __c = b'\x00\x00\x00\x00\x00\x00\x00\x05\x00\x00\xf5\xe4\xd3\xc2\xb1\x09\x00\x00\x00\x01\x11\x00\x00\x00\x07\x00\xf5\xe4\xd3\xc2\xb1\x09\x00\x00\x00\x06\x9a\x1b\x2c\x3d\x4e\xf7'
+ __d = b'\x00\x00\x00\x05\xff\x00\x00\x00\x05\x11\x22\x33\x44\x55\xff\x00\x00\x00\x0a\x00\xf0\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x03\x63\x61\x74\x00\x00\x00\x03\x61\x2c\x62'
def test_1_encode(self):
msg = Message()
@@ -38,63 +39,65 @@ class MessageTest (unittest.TestCase):
msg.add_string('q')
msg.add_string('hello')
msg.add_string('x' * 1000)
- self.assertEquals(str(msg), self.__a)
+ self.assertEqual(msg.asbytes(), self.__a)
msg = Message()
msg.add_boolean(True)
msg.add_boolean(False)
- msg.add_byte('\xf3')
- msg.add_bytes('\x00\x3f')
+ msg.add_byte(byte_chr(0xf3))
+
+ msg.add_bytes(zero_byte + byte_chr(0x3f))
msg.add_list(['huey', 'dewey', 'louie'])
- self.assertEquals(str(msg), self.__b)
+ self.assertEqual(msg.asbytes(), self.__b)
msg = Message()
msg.add_int64(5)
- msg.add_int64(0xf5e4d3c2b109L)
+ msg.add_int64(0xf5e4d3c2b109)
msg.add_mpint(17)
- msg.add_mpint(0xf5e4d3c2b109L)
- msg.add_mpint(-0x65e4d3c2b109L)
- self.assertEquals(str(msg), self.__c)
+ msg.add_mpint(0xf5e4d3c2b109)
+ msg.add_mpint(-0x65e4d3c2b109)
+ self.assertEqual(msg.asbytes(), self.__c)
def test_2_decode(self):
msg = Message(self.__a)
- self.assertEquals(msg.get_int(), 23)
- self.assertEquals(msg.get_int(), 123789456)
- self.assertEquals(msg.get_string(), 'q')
- self.assertEquals(msg.get_string(), 'hello')
- self.assertEquals(msg.get_string(), 'x' * 1000)
+ self.assertEqual(msg.get_int(), 23)
+ self.assertEqual(msg.get_int(), 123789456)
+ self.assertEqual(msg.get_text(), 'q')
+ self.assertEqual(msg.get_text(), 'hello')
+ self.assertEqual(msg.get_text(), 'x' * 1000)
msg = Message(self.__b)
- self.assertEquals(msg.get_boolean(), True)
- self.assertEquals(msg.get_boolean(), False)
- self.assertEquals(msg.get_byte(), '\xf3')
- self.assertEquals(msg.get_bytes(2), '\x00\x3f')
- self.assertEquals(msg.get_list(), ['huey', 'dewey', 'louie'])
+ self.assertEqual(msg.get_boolean(), True)
+ self.assertEqual(msg.get_boolean(), False)
+ self.assertEqual(msg.get_byte(), byte_chr(0xf3))
+ self.assertEqual(msg.get_bytes(2), zero_byte + byte_chr(0x3f))
+ self.assertEqual(msg.get_list(), ['huey', 'dewey', 'louie'])
msg = Message(self.__c)
- self.assertEquals(msg.get_int64(), 5)
- self.assertEquals(msg.get_int64(), 0xf5e4d3c2b109L)
- self.assertEquals(msg.get_mpint(), 17)
- self.assertEquals(msg.get_mpint(), 0xf5e4d3c2b109L)
- self.assertEquals(msg.get_mpint(), -0x65e4d3c2b109L)
+ self.assertEqual(msg.get_int64(), 5)
+ self.assertEqual(msg.get_int64(), 0xf5e4d3c2b109)
+ self.assertEqual(msg.get_mpint(), 17)
+ self.assertEqual(msg.get_mpint(), 0xf5e4d3c2b109)
+ self.assertEqual(msg.get_mpint(), -0x65e4d3c2b109)
def test_3_add(self):
msg = Message()
msg.add(5)
- msg.add(0x1122334455L)
+ msg.add(0x1122334455)
+ msg.add(0xf00000000000000000)
msg.add(True)
msg.add('cat')
msg.add(['a', 'b'])
- self.assertEquals(str(msg), self.__d)
+ self.assertEqual(msg.asbytes(), self.__d)
def test_4_misc(self):
msg = Message(self.__d)
- self.assertEquals(msg.get_int(), 5)
- self.assertEquals(msg.get_mpint(), 0x1122334455L)
- self.assertEquals(msg.get_so_far(), self.__d[:13])
- self.assertEquals(msg.get_remainder(), self.__d[13:])
+ self.assertEqual(msg.get_int(), 5)
+ self.assertEqual(msg.get_int(), 0x1122334455)
+ self.assertEqual(msg.get_int(), 0xf00000000000000000)
+ self.assertEqual(msg.get_so_far(), self.__d[:29])
+ self.assertEqual(msg.get_remainder(), self.__d[29:])
msg.rewind()
- self.assertEquals(msg.get_int(), 5)
- self.assertEquals(msg.get_so_far(), self.__d[:4])
- self.assertEquals(msg.get_remainder(), self.__d[4:])
-
+ self.assertEqual(msg.get_int(), 5)
+ self.assertEqual(msg.get_so_far(), self.__d[:4])
+ self.assertEqual(msg.get_remainder(), self.__d[4:])