def test_boundedFile1(self): buf = StringIO.StringIO() bfp = BoundedFile(buf, 10) # check boundary condition when cursize == maxsize bfp.write('1234567890') self.assert_(not bfp.isOverflow()) self.assertEqual(len(buf.getvalue()), 10) bfp.write('a') self.assert_(bfp.isOverflow()) self.assertEqual(len(buf.getvalue()), 10)
def test_boundedFile(self): buf = StringIO.StringIO() bfp = BoundedFile(buf, 10) bfp.write('12345') self.assert_(not bfp.isOverflow()) self.assertEqual(len(buf.getvalue()), 5) bfp.write('678') self.assert_(not bfp.isOverflow()) self.assertEqual(len(buf.getvalue()), 8) bfp.write('90ab') self.assert_(bfp.isOverflow()) self.assertEqual(len(buf.getvalue()), 8) # although bfp is still 2 characters below maxsize # make sure once it is overflowed you cannot write anymore bfp.write('c') self.assert_(bfp.isOverflow()) self.assertEqual(len(buf.getvalue()), 8)