Пример #1
0
 def makeFile(self,contents,mode,start=0,stop=None,resizable=False):
     s = StringIO(contents)
     f = Slice(s,start,stop,resizable=resizable,mode=mode)
     def getvalue():
         val = s.getvalue()
         if stop:
             val = val[:f.stop]
         if start:
             val = val[f.start:]
         return val
     f.getvalue = getvalue
     return f
Пример #2
0
    def makeFile(self, contents, mode, start=0, stop=None, resizable=False):
        s = StringIO(contents)
        f = Slice(s, start, stop, resizable=resizable, mode=mode)

        def getvalue():
            val = s.getvalue()
            if stop:
                val = val[:f.stop]
            if start:
                val = val[f.start:]
            return val

        f.getvalue = getvalue
        return f
Пример #3
0
 def test_resizability(self):
     """Test that resizing slices works correctly."""
     #  By default, can't write beyond end of slice.
     f = Slice(StringIO("mytestdata"), start=2, stop=6)
     f.write("TE")
     f.seek(0)
     self.assertEquals(f.read(), "TEst")
     self.assertEquals(f._fileobj.getvalue(), "myTEstdata")
     f.seek(0)
     self.assertRaises(IOError, f.write, "TESTDATA")
     self.assertEquals(f._fileobj.getvalue(), "myTESTdata")
     # Resizability allows data to be overwritten
     f = Slice(StringIO("mytestdata"), start=2, stop=6, resizable=True)
     f.write("TESTDA")
     self.assertEquals(f._fileobj.getvalue(), "myTESTDAta")
     self.assertEquals(f.stop, 8)
Пример #4
0
 def test_resizability(self):
     """Test that resizing slices works correctly."""
     #  By default, can't write beyond end of slice.
     f = Slice(StringIO("mytestdata"),start=2,stop=6)
     f.write("TE")
     f.seek(0)
     self.assertEquals(f.read(),"TEst")
     self.assertEquals(f._fileobj.getvalue(),"myTEstdata")
     f.seek(0)
     self.assertRaises(IOError,f.write,"TESTDATA")
     self.assertEquals(f._fileobj.getvalue(),"myTESTdata")
     # Resizability allows data to be overwritten
     f = Slice(StringIO("mytestdata"),start=2,stop=6,resizable=True)
     f.write("TESTDA")
     self.assertEquals(f._fileobj.getvalue(),"myTESTDAta")
     self.assertEquals(f.stop,8)