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)
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)
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)
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)
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)
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
def as_NamedStream(self, name): return util.NamedStream(self.as_cStringIO(name), self.filenames[name])