summaryrefslogtreecommitdiffhomepage
path: root/tests
diff options
context:
space:
mode:
authorJeff Forcier <jeff@bitprophet.org>2014-04-24 09:34:00 -0700
committerJeff Forcier <jeff@bitprophet.org>2014-04-24 09:34:00 -0700
commit1321bc41dfe76a01c98f50c91e429eb69b06ed5e (patch)
treebeb74ec5cbd37091c7dd6a2cd2bbd12fdbdd3740 /tests
parenta1d291e04777fb963c1ac76d0d77b3ff7fe0732b (diff)
parentae30b31721fc461c46fc23b768703a3f29ee9939 (diff)
Merge branch '1.13'
Diffstat (limited to 'tests')
-rwxr-xr-xtests/test_file.py45
-rwxr-xr-xtests/test_sftp.py10
-rw-r--r--tests/test_sftp_big.py4
3 files changed, 32 insertions, 27 deletions
diff --git a/tests/test_file.py b/tests/test_file.py
index e11d7fd5..c6edd7af 100755
--- a/tests/test_file.py
+++ b/tests/test_file.py
@@ -53,7 +53,7 @@ class BufferedFileTest (unittest.TestCase):
def test_1_simple(self):
f = LoopbackFile('r')
try:
- f.write('hi')
+ f.write(b'hi')
self.assertTrue(False, 'no exception on write to read-only file')
except:
pass
@@ -69,7 +69,7 @@ class BufferedFileTest (unittest.TestCase):
def test_2_readline(self):
f = LoopbackFile('r+U')
- f.write('First line.\nSecond line.\r\nThird line.\nFinal line non-terminated.')
+ f.write(b'First line.\nSecond line.\r\nThird line.\nFinal line non-terminated.')
self.assertEqual(f.readline(), 'First line.\n')
# universal newline mode should convert this linefeed:
self.assertEqual(f.readline(), 'Second line.\n')
@@ -93,9 +93,9 @@ class BufferedFileTest (unittest.TestCase):
try to trick the linefeed detector.
"""
f = LoopbackFile('r+U')
- f.write('First line.\r')
+ f.write(b'First line.\r')
self.assertEqual(f.readline(), 'First line.\n')
- f.write('\nSecond.\r\n')
+ f.write(b'\nSecond.\r\n')
self.assertEqual(f.readline(), 'Second.\n')
f.close()
self.assertEqual(f.newlines, crlf)
@@ -105,7 +105,7 @@ class BufferedFileTest (unittest.TestCase):
verify that write buffering is on.
"""
f = LoopbackFile('r+', 1)
- f.write('Complete line.\nIncomplete line.')
+ f.write(b'Complete line.\nIncomplete line.')
self.assertEqual(f.readline(), 'Complete line.\n')
self.assertEqual(f.readline(), '')
f.write('..\n')
@@ -118,12 +118,12 @@ class BufferedFileTest (unittest.TestCase):
"""
f = LoopbackFile('r+', 512)
f.write('Not\nquite\n512 bytes.\n')
- self.assertEqual(f.read(1), '')
+ self.assertEqual(f.read(1), b'')
f.flush()
- self.assertEqual(f.read(5), 'Not\nq')
- self.assertEqual(f.read(10), 'uite\n512 b')
- self.assertEqual(f.read(9), 'ytes.\n')
- self.assertEqual(f.read(3), '')
+ self.assertEqual(f.read(5), b'Not\nq')
+ self.assertEqual(f.read(10), b'uite\n512 b')
+ self.assertEqual(f.read(9), b'ytes.\n')
+ self.assertEqual(f.read(3), b'')
f.close()
def test_6_buffering(self):
@@ -131,12 +131,12 @@ class BufferedFileTest (unittest.TestCase):
verify that flushing happens automatically on buffer crossing.
"""
f = LoopbackFile('r+', 16)
- f.write('Too small.')
- self.assertEqual(f.read(4), '')
- f.write(' ')
- self.assertEqual(f.read(4), '')
- f.write('Enough.')
- self.assertEqual(f.read(20), 'Too small. Enough.')
+ f.write(b'Too small.')
+ self.assertEqual(f.read(4), b'')
+ f.write(b' ')
+ self.assertEqual(f.read(4), b'')
+ f.write(b'Enough.')
+ self.assertEqual(f.read(20), b'Too small. Enough.')
f.close()
def test_7_read_all(self):
@@ -144,9 +144,14 @@ class BufferedFileTest (unittest.TestCase):
verify that read(-1) returns everything left in the file.
"""
f = LoopbackFile('r+', 16)
- f.write('The first thing you need to do is open your eyes. ')
- f.write('Then, you need to close them again.\n')
+ f.write(b'The first thing you need to do is open your eyes. ')
+ f.write(b'Then, you need to close them again.\n')
s = f.read(-1)
- self.assertEqual(s, 'The first thing you need to do is open your eyes. Then, you ' +
- 'need to close them again.\n')
+ self.assertEqual(s, b'The first thing you need to do is open your eyes. Then, you ' +
+ b'need to close them again.\n')
f.close()
+
+if __name__ == '__main__':
+ from unittest import main
+ main()
+
diff --git a/tests/test_sftp.py b/tests/test_sftp.py
index e0534eb0..720b8215 100755
--- a/tests/test_sftp.py
+++ b/tests/test_sftp.py
@@ -405,7 +405,7 @@ class SFTPTest (unittest.TestCase):
self.assertEqual(sftp.stat(FOLDER + '/testing.txt').st_size, 13)
with sftp.open(FOLDER + '/testing.txt', 'r') as f:
data = f.read(20)
- self.assertEqual(data, 'hello kiddy.\n')
+ self.assertEqual(data, b'hello kiddy.\n')
finally:
sftp.remove(FOLDER + '/testing.txt')
@@ -466,8 +466,8 @@ class SFTPTest (unittest.TestCase):
f.write('?\n')
with sftp.open(FOLDER + '/happy.txt', 'r') as f:
- self.assertEqual(f.readline(), 'full line?\n')
- self.assertEqual(f.read(7), 'partial')
+ self.assertEqual(f.readline(), u'full line?\n')
+ self.assertEqual(f.read(7), b'partial')
finally:
try:
sftp.remove(FOLDER + '/happy.txt')
@@ -662,8 +662,8 @@ class SFTPTest (unittest.TestCase):
fd, localname = mkstemp()
os.close(fd)
- text = 'All I wanted was a plastic bunny rabbit.\n'
- with open(localname, 'w') as f:
+ text = b'All I wanted was a plastic bunny rabbit.\n'
+ with open(localname, 'wb') as f:
f.write(text)
saved_progress = []
diff --git a/tests/test_sftp_big.py b/tests/test_sftp_big.py
index 521fbdc8..abed27b8 100644
--- a/tests/test_sftp_big.py
+++ b/tests/test_sftp_big.py
@@ -85,7 +85,7 @@ class BigSFTPTest (unittest.TestCase):
write a 1MB file with no buffering.
"""
sftp = get_sftp()
- kblob = (1024 * 'x')
+ kblob = (1024 * b'x')
start = time.time()
try:
with sftp.open('%s/hongry.txt' % FOLDER, 'w') as f:
@@ -231,7 +231,7 @@ class BigSFTPTest (unittest.TestCase):
without using it, to verify that paramiko doesn't get confused.
"""
sftp = get_sftp()
- kblob = (1024 * 'x')
+ kblob = (1024 * b'x')
try:
with sftp.open('%s/hongry.txt' % FOLDER, 'w') as f:
f.set_pipelined(True)