示例#1
0
 def testClosingForce(self):
     obj = cStringIO.StringIO("".join(self.text))
     ns = util.NamedStream(obj, self.textname)
     assert_equal(ns.closed, False)
     ns.close()
     assert_equal(ns.closed, False)
     ns.close(force=True)
     assert_equal(ns.closed, True)
示例#2
0
 def testNamedStream(self):
     ns = util.NamedStream(cStringIO.StringIO(), self.filename)
     fn = util.filename(ns, ext=self.ext)
     # assert_equal replace by this if loop to avoid segfault on some systems
     if fn != ns:
         raise AssertionError("fn and ns are different")
     assert_equal(str(fn), self.filename2)
     assert_equal(ns.name, self.filename2)
示例#3
0
 def testFile_read(self):
     obj = open(self.filename, 'r')
     ns = util.NamedStream(obj, self.filename)
     assert_equal(ns.name, self.filename)
     assert_equal(str(ns), self.filename)
     assert_equal(len(ns.readlines()), self.numlines)
     ns.reset()
     assert_equal(len(ns.readlines()), self.numlines)
     ns.close(force=True)
示例#4
0
 def testcStringIO_read(self):
     obj = cStringIO.StringIO("".join(self.text))
     ns = util.NamedStream(obj, self.textname)
     assert_equal(ns.name, self.textname)
     assert_equal(str(ns), self.textname)
     assert_equal(len(ns.readlines()), self.numtextlines)
     ns.reset()
     assert_equal(len(ns.readlines()), self.numtextlines)
     ns.close(force=True)
示例#5
0
 def testcStringIO_write(self):
     obj = cStringIO.StringIO()
     ns = util.NamedStream(obj, self.textname)
     ns.writelines(self.text)
     assert_equal(ns.name, self.textname)
     assert_equal(str(ns), self.textname)
     ns.reset()
     assert_equal(len(ns.readlines()), len(self.text))
     ns.reset()
     assert_equal(ns.read(20), "".join(self.text)[:20])
     ns.close(force=True)
示例#6
0
    def testFile_write(self):
        fd, outfile = tempfile.mkstemp(suffix=".txt")
        os.close(fd)
        try:
            obj = open(outfile, "w")
            ns = util.NamedStream(obj, outfile, close=True)
            ns.writelines(self.text)
            ns.close()
            text = open(outfile).readlines()

            assert_equal(ns.name, outfile)
            assert_equal(str(ns), outfile)
            assert_equal(len(text), len(self.text))
            assert_equal("".join(text), "".join(self.text))
        finally:
            ns.close()
            obj.close()
            try:
                os.unlink(outfile)
            except OSError:
                pass
示例#7
0
 def as_NamedStream(self, name):
     return util.NamedStream(self.as_cStringIO(name), self.filenames[name])