Remove unnecessary vars for open

This commit is contained in:
Scott Maxwell 2013-11-19 09:29:08 -08:00
parent 106f9ea444
commit dcc78768bf
1 changed files with 9 additions and 17 deletions

View File

@ -231,7 +231,7 @@ class SFTPTest (unittest.TestCase):
f.write('content!\n') f.write('content!\n')
sftp.rename(FOLDER + '/first.txt', FOLDER + '/second.txt') sftp.rename(FOLDER + '/first.txt', FOLDER + '/second.txt')
try: try:
f = sftp.open(FOLDER + '/first.txt', 'r') sftp.open(FOLDER + '/first.txt', 'r')
self.assertTrue(False, 'no exception on reading nonexistent file') self.assertTrue(False, 'no exception on reading nonexistent file')
except IOError: except IOError:
pass pass
@ -254,12 +254,11 @@ class SFTPTest (unittest.TestCase):
remove the folder and verify that we can't create a file in it anymore. remove the folder and verify that we can't create a file in it anymore.
""" """
sftp.mkdir(FOLDER + '/subfolder') sftp.mkdir(FOLDER + '/subfolder')
f = sftp.open(FOLDER + '/subfolder/test', 'w') sftp.open(FOLDER + '/subfolder/test', 'w').close()
f.close()
sftp.remove(FOLDER + '/subfolder/test') sftp.remove(FOLDER + '/subfolder/test')
sftp.rmdir(FOLDER + '/subfolder') sftp.rmdir(FOLDER + '/subfolder')
try: try:
f = sftp.open(FOLDER + '/subfolder/test') sftp.open(FOLDER + '/subfolder/test')
# shouldn't be able to create that file # shouldn't be able to create that file
self.assertTrue(False, 'no exception at dummy file creation') self.assertTrue(False, 'no exception at dummy file creation')
except IOError: except IOError:
@ -271,14 +270,9 @@ class SFTPTest (unittest.TestCase):
and those files show up in sftp.listdir. and those files show up in sftp.listdir.
""" """
try: try:
f = sftp.open(FOLDER + '/duck.txt', 'w') sftp.open(FOLDER + '/duck.txt', 'w').close()
f.close() sftp.open(FOLDER + '/fish.txt', 'w').close()
sftp.open(FOLDER + '/tertiary.py', 'w').close()
f = sftp.open(FOLDER + '/fish.txt', 'w')
f.close()
f = sftp.open(FOLDER + '/tertiary.py', 'w')
f.close()
x = sftp.listdir(FOLDER) x = sftp.listdir(FOLDER)
self.assertEqual(len(x), 3) self.assertEqual(len(x), 3)
@ -607,12 +601,11 @@ class SFTPTest (unittest.TestCase):
""" """
verify that the 'x' flag works when opening a file. verify that the 'x' flag works when opening a file.
""" """
f = sftp.open(FOLDER + '/unusual.txt', 'wx') sftp.open(FOLDER + '/unusual.txt', 'wx').close()
f.close()
try: try:
try: try:
f = sftp.open(FOLDER + '/unusual.txt', 'wx') sftp.open(FOLDER + '/unusual.txt', 'wx')
self.fail('expected exception') self.fail('expected exception')
except IOError: except IOError:
pass pass
@ -648,8 +641,7 @@ class SFTPTest (unittest.TestCase):
""" """
verify that readv at the end of the file doesn't essplode. verify that readv at the end of the file doesn't essplode.
""" """
f = sftp.open(FOLDER + '/zero', 'w') sftp.open(FOLDER + '/zero', 'w').close()
f.close()
try: try:
with sftp.open(FOLDER + '/zero', 'r') as f: with sftp.open(FOLDER + '/zero', 'r') as f:
f.readv([(0, 12)]) f.readv([(0, 12)])