summaryrefslogtreecommitdiffhomepage
path: root/tests
diff options
context:
space:
mode:
authorScott Maxwell <scott@codecobblers.com>2013-10-31 17:20:27 -0700
committerScott Maxwell <scott@codecobblers.com>2013-10-31 17:20:27 -0700
commit0677ea76cdb1320fe6d1a08cdfa8c145f3818ab0 (patch)
tree65961e23e2b848d48deb53b254661a2d60cebab1 /tests
parent8e1a7ef4d8278421da43eb8101ae68bec29c5b07 (diff)
Fixes for test_sftp
Diffstat (limited to 'tests')
-rwxr-xr-xtests/test_sftp.py72
1 files changed, 38 insertions, 34 deletions
diff --git a/tests/test_sftp.py b/tests/test_sftp.py
index c80967d1..64c727a6 100755
--- a/tests/test_sftp.py
+++ b/tests/test_sftp.py
@@ -31,6 +31,7 @@ import warnings
import sys
import threading
import unittest
+from tempfile import mkstemp
import paramiko
from paramiko.common import *
@@ -234,7 +235,7 @@ class SFTPTest (unittest.TestCase):
sftp.rename(FOLDER + '/first.txt', FOLDER + '/second.txt')
try:
f = sftp.open(FOLDER + '/first.txt', 'r')
- self.assert_(False, 'no exception on reading nonexistent file')
+ self.assertTrue(False, 'no exception on reading nonexistent file')
except IOError:
pass
f = sftp.open(FOLDER + '/second.txt', 'r')
@@ -264,7 +265,7 @@ class SFTPTest (unittest.TestCase):
try:
f = sftp.open(FOLDER + '/subfolder/test')
# shouldn't be able to create that file
- self.assert_(False, 'no exception at dummy file creation')
+ self.assertTrue(False, 'no exception at dummy file creation')
except IOError:
pass
@@ -285,10 +286,10 @@ class SFTPTest (unittest.TestCase):
x = sftp.listdir(FOLDER)
self.assertEqual(len(x), 3)
- self.assert_('duck.txt' in x)
- self.assert_('fish.txt' in x)
- self.assert_('tertiary.py' in x)
- self.assert_('random' not in x)
+ self.assertTrue('duck.txt' in x)
+ self.assertTrue('fish.txt' in x)
+ self.assertTrue('tertiary.py' in x)
+ self.assertTrue('random' not in x)
finally:
sftp.remove(FOLDER + '/duck.txt')
sftp.remove(FOLDER + '/fish.txt')
@@ -454,7 +455,7 @@ class SFTPTest (unittest.TestCase):
self.assertEqual(sftp.stat(FOLDER + '/link.txt').st_size, 9)
# the sftp server may be hiding extra path members from us, so the
# length may be longer than we expect:
- self.assert_(sftp.lstat(FOLDER + '/link2.txt').st_size >= len(abs_path))
+ self.assertTrue(sftp.lstat(FOLDER + '/link2.txt').st_size >= len(abs_path))
self.assertEqual(sftp.stat(FOLDER + '/link2.txt').st_size, 9)
self.assertEqual(sftp.stat(FOLDER + '/original.txt').st_size, 9)
finally:
@@ -499,10 +500,10 @@ class SFTPTest (unittest.TestCase):
error.
"""
pwd = sftp.normalize('.')
- self.assert_(len(pwd) > 0)
+ self.assertTrue(len(pwd) > 0)
f = sftp.normalize('./' + FOLDER)
- self.assert_(len(f) > 0)
- self.assertEquals(os.path.join(pwd, FOLDER), f)
+ self.assertTrue(len(f) > 0)
+ self.assertEqual(os.path.join(pwd, FOLDER), f)
def test_F_mkdir(self):
"""
@@ -511,19 +512,19 @@ class SFTPTest (unittest.TestCase):
try:
sftp.mkdir(FOLDER + '/subfolder')
except:
- self.assert_(False, 'exception creating subfolder')
+ self.assertTrue(False, 'exception creating subfolder')
try:
sftp.mkdir(FOLDER + '/subfolder')
- self.assert_(False, 'no exception overwriting subfolder')
+ self.assertTrue(False, 'no exception overwriting subfolder')
except IOError:
pass
try:
sftp.rmdir(FOLDER + '/subfolder')
except:
- self.assert_(False, 'exception removing subfolder')
+ self.assertTrue(False, 'exception removing subfolder')
try:
sftp.rmdir(FOLDER + '/subfolder')
- self.assert_(False, 'no exception removing nonexistent subfolder')
+ self.assertTrue(False, 'no exception removing nonexistent subfolder')
except IOError:
pass
@@ -538,17 +539,17 @@ class SFTPTest (unittest.TestCase):
sftp.mkdir(FOLDER + '/alpha')
sftp.chdir(FOLDER + '/alpha')
sftp.mkdir('beta')
- self.assertEquals(root + FOLDER + '/alpha', sftp.getcwd())
- self.assertEquals(['beta'], sftp.listdir('.'))
+ self.assertEqual(root + FOLDER + '/alpha', sftp.getcwd())
+ self.assertEqual(['beta'], sftp.listdir('.'))
sftp.chdir('beta')
f = sftp.open('fish', 'w')
f.write('hello\n')
f.close()
sftp.chdir('..')
- self.assertEquals(['fish'], sftp.listdir('beta'))
+ self.assertEqual(['fish'], sftp.listdir('beta'))
sftp.chdir('..')
- self.assertEquals(['fish'], sftp.listdir('alpha/beta'))
+ self.assertEqual(['fish'], sftp.listdir('alpha/beta'))
finally:
sftp.chdir(root)
try:
@@ -570,8 +571,9 @@ class SFTPTest (unittest.TestCase):
"""
warnings.filterwarnings('ignore', 'tempnam.*')
- localname = os.tempnam()
- text = 'All I wanted was a plastic bunny rabbit.\n'
+ fd, localname = mkstemp()
+ os.close(fd)
+ text = b('All I wanted was a plastic bunny rabbit.\n')
f = open(localname, 'wb')
f.write(text)
f.close()
@@ -581,19 +583,20 @@ class SFTPTest (unittest.TestCase):
sftp.put(localname, FOLDER + '/bunny.txt', progress_callback)
f = sftp.open(FOLDER + '/bunny.txt', 'r')
- self.assertEquals(text, f.read(128))
+ self.assertEqual(text, f.read(128))
f.close()
- self.assertEquals((41, 41), saved_progress[-1])
+ self.assertEqual((41, 41), saved_progress[-1])
os.unlink(localname)
- localname = os.tempnam()
+ fd, localname = mkstemp()
+ os.close(fd)
saved_progress = []
sftp.get(FOLDER + '/bunny.txt', localname, progress_callback)
f = open(localname, 'rb')
- self.assertEquals(text, f.read(128))
+ self.assertEqual(text, f.read(128))
f.close()
- self.assertEquals((41, 41), saved_progress[-1])
+ self.assertEqual((41, 41), saved_progress[-1])
os.unlink(localname)
sftp.unlink(FOLDER + '/bunny.txt')
@@ -611,11 +614,11 @@ class SFTPTest (unittest.TestCase):
try:
f = sftp.open(FOLDER + '/kitty.txt', 'r')
sum = f.check('sha1')
- self.assertEquals('91059CFC6615941378D413CB5ADAF4C5EB293402', hexlify(sum).upper())
+ self.assertEqual('91059CFC6615941378D413CB5ADAF4C5EB293402', hexlify(sum).upper())
sum = f.check('md5', 0, 512)
- self.assertEquals('93DE4788FCA28D471516963A1FE3856A', hexlify(sum).upper())
+ self.assertEqual('93DE4788FCA28D471516963A1FE3856A', hexlify(sum).upper())
sum = f.check('md5', 0, 0, 510)
- self.assertEquals('EB3B45B8CD55A0707D99B177544A319F373183D241432BB2157AB9E46358C4AC90370B5CADE5D90336FC1716F90B36D6',
+ self.assertEqual('EB3B45B8CD55A0707D99B177544A319F373183D241432BB2157AB9E46358C4AC90370B5CADE5D90336FC1716F90B36D6',
hexlify(sum).upper())
f.close()
finally:
@@ -650,7 +653,7 @@ class SFTPTest (unittest.TestCase):
sftp.open(FOLDER + '/\xc3\xbcnic\xc3\xb8\x64\x65', 'r')
except Exception:
e = sys.exc_info()[1]
- self.fail('exception ' + e)
+ self.fail('exception ' + str(e))
sftp.unlink(FOLDER + '/\xc3\xbcnic\xc3\xb8\x64\x65')
def test_L_utf8_chdir(self):
@@ -689,8 +692,9 @@ class SFTPTest (unittest.TestCase):
"""
warnings.filterwarnings('ignore', 'tempnam.*')
- localname = os.tempnam()
- text = 'All I wanted was a plastic bunny rabbit.\n'
+ fd, localname = mkstemp()
+ os.close(fd)
+ text = b('All I wanted was a plastic bunny rabbit.\n')
f = open(localname, 'wb')
f.write(text)
f.close()
@@ -699,12 +703,12 @@ class SFTPTest (unittest.TestCase):
saved_progress.append((x, y))
res = sftp.put(localname, FOLDER + '/bunny.txt', progress_callback, False)
- self.assertEquals(SFTPAttributes().attr, res.attr)
+ self.assertEqual(SFTPAttributes().attr, res.attr)
f = sftp.open(FOLDER + '/bunny.txt', 'r')
- self.assertEquals(text, f.read(128))
+ self.assertEqual(text, f.read(128))
f.close()
- self.assertEquals((41, 41), saved_progress[-1])
+ self.assertEqual((41, 41), saved_progress[-1])
os.unlink(localname)
sftp.unlink(FOLDER + '/bunny.txt')