summaryrefslogtreecommitdiff
path: root/rdiff-backup/testing/iterfiletest.py
blob: 38dca4d323dbe53512082233b6d854ddfa25a9a5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import unittest, StringIO
execfile("commontest.py")
rbexec("iterfile.py")


class testIterFile(unittest.TestCase):
	def setUp(self):
		self.iter1maker = lambda: iter(range(50))
		self.iter2maker = lambda: iter(map(str, range(50)))

	def testConversion(self):
		"""Test iter to file conversion"""
		for itm in [self.iter1maker, self.iter2maker]:
			assert Iter.equal(itm(),
							  IterWrappingFile(FileWrappingIter(itm())))

class testBufferedRead(unittest.TestCase):
	def testBuffering(self):
		"""Test buffering a StringIO"""
		fp = StringIO.StringIO("12345678"*10000)
		bfp = BufferedRead(fp)
		assert bfp.read(5) == "12345"
		assert bfp.read(4) == "6781"
		assert len(bfp.read(75000)) == 75000


if __name__ == "__main__": unittest.main()