diff options
author | Sybren A. Stüvel <sybren@stuvel.eu> | 2011-07-31 20:47:49 +0200 |
---|---|---|
committer | Sybren A. Stüvel <sybren@stuvel.eu> | 2011-07-31 20:47:49 +0200 |
commit | 3200f895745919a6074505dd40c8d0f88b01836a (patch) | |
tree | 864f5a2722340061553407cdbcb33972cf44d7bc /tests/test_varblock.py | |
parent | fa345b65cf1951d8177fa9f4f90c06e1249e5f6f (diff) | |
download | rsa-3200f895745919a6074505dd40c8d0f88b01836a.tar.gz |
Made hashing efficient for large files
Diffstat (limited to 'tests/test_varblock.py')
-rw-r--r-- | tests/test_varblock.py | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/tests/test_varblock.py b/tests/test_varblock.py new file mode 100644 index 0000000..d8addb4 --- /dev/null +++ b/tests/test_varblock.py @@ -0,0 +1,77 @@ +'''Tests varblock operations.''' + +from StringIO import StringIO +import unittest + +import rsa +from rsa import varblock + +class VarintTest(unittest.TestCase): + + def test_read_varint(self): + + encoded = '\xac\x02crummy' + infile = StringIO(encoded) + + (decoded, read) = varblock.read_varint(infile) + + # Test the returned values + self.assertEqual(300, decoded) + self.assertEqual(2, read) + + # The rest of the file should be untouched + self.assertEqual('crummy', infile.read()) + + def test_read_zero(self): + + encoded = '\x00crummy' + infile = StringIO(encoded) + + (decoded, read) = varblock.read_varint(infile) + + # Test the returned values + self.assertEqual(0, decoded) + self.assertEqual(1, read) + + # The rest of the file should be untouched + self.assertEqual('crummy', infile.read()) + + def test_write_varint(self): + + expected = '\xac\x02' + outfile = StringIO() + + written = varblock.write_varint(outfile, 300) + + # Test the returned values + self.assertEqual(expected, outfile.getvalue()) + self.assertEqual(2, written) + + + def test_write_zero(self): + + outfile = StringIO() + written = varblock.write_varint(outfile, 0) + + # Test the returned values + self.assertEqual('\x00', outfile.getvalue()) + self.assertEqual(1, written) + + +class VarblockTest(unittest.TestCase): + + def test_yield_varblock(self): + infile = StringIO('\x01\x0512345\x06Sybren') + + varblocks = list(varblock.yield_varblocks(infile)) + self.assertEqual(['12345', 'Sybren'], varblocks) + +class FixedblockTest(unittest.TestCase): + + def test_yield_fixedblock(self): + + infile = StringIO('123456Sybren') + + fixedblocks = list(varblock.yield_fixedblocks(infile, 6)) + self.assertEqual(['123456', 'Sybren'], fixedblocks) + |