FIX unittest test_copy_data_bytesio().

* CHANGE unittest test_copy_data_bytesio() to actually check that the output
   data matches the original message string given to io.BytesIO().
 * REMOVE class test.test_gnupg.ResultStringIO, as it is now not used
   anywhere.
 * FIXES test_copy_data_bytesio() not actually testing what it was supposed
   to.
fix/24-enc-to-file
Isis Lovecruft 2013-10-08 08:46:19 +00:00
parent 0166b4bc6a
commit 903ffd3906
No known key found for this signature in database
GPG Key ID: 5C17776E27F7E84D
1 changed files with 17 additions and 13 deletions

View File

@ -152,13 +152,6 @@ def compare_keys(k1, k2):
return k1 != k2
class ResultStringIO(io.StringIO):
def __init__(self, init_string):
super(ResultStringIO, self).__init__(init_string)
def write(self, data):
super(ResultStringIO, self).write(unicode(data))
class GPGTestCase(unittest.TestCase):
""":class:`unittest.TestCase <TestCase>`s for python-gnupg."""
@ -341,17 +334,28 @@ class GPGTestCase(unittest.TestCase):
def test_copy_data_bytesio(self):
"""Test that _copy_data() is able to duplicate byte streams."""
message = "This is a BytesIO string string in memory."
message = "This is a BytesIO string."
instream = io.BytesIO(message)
self.assertEqual(unicode(message), instream.getvalue())
outstream = ResultStringIO(u'result:')
copied = outstream
out_filename = 'test-copy-data-bytesio'
# Create the test file:
outfile = os.path.join(os.getcwdu(), out_filename)
outstream = open(outfile, 'w+')
# _copy_data() will close both file descriptors
_util._copy_data(instream, outstream)
self.assertTrue(outstream.readable())
self.assertTrue(outstream.closed)
self.assertFalse(instream.closed)
self.assertTrue(copied.closed)
#self.assertEqual(instream.getvalue()[6:], outstream.getvalue())
self.assertTrue(os.path.isfile(outfile))
with open(outfile) as out:
out.flush()
out.seek(0)
output = out.read()
self.assertEqual(message, output)
def generate_key_input(self, real_name, email_domain, key_length=None,
key_type=None, subkey_type=None, passphrase=None):