Пример #1
0
    def test_close(self):
        """close() flushes the buffer"""

        b = BufferedWriter(self.test_fp, buf_size=2)
        b.write("1")
        b.close()
        content = open(self.test_fp, "r").readlines()
        self.assertEquals(content, ["1"])
Пример #2
0
    def test_close(self):
        """close() flushes the buffer"""

        b = BufferedWriter(self.test_fp, buf_size=2)
        b.write("1")
        b.close()
        content = open(self.test_fp, "r").readlines()
        self.assertEquals(content, ["1"])
Пример #3
0
    def test_write(self):
        """BufferedWriter writes nothing until max buffer reached."""

        b = BufferedWriter(self.test_fp, buf_size=2)
        b.write("1")
        content = open(self.test_fp, "r").readlines()
        self.assertEquals(content, [])

        # still nothing
        b.write("2")
        content = open(self.test_fp, "r").readlines()
        self.assertEquals(content, [])

        # finally, buffer is flushed
        b.write("3")
        content = open(self.test_fp, "r").readlines()
        self.assertEquals(content, ["123"])
Пример #4
0
    def test_write(self):
        """BufferedWriter writes nothing until max buffer reached."""

        b = BufferedWriter(self.test_fp, buf_size=2)
        b.write("1")
        content = open(self.test_fp, "r").readlines()
        self.assertEquals(content, [])

        # still nothing
        b.write("2")
        content = open(self.test_fp, "r").readlines()
        self.assertEquals(content, [])

        # finally, buffer is flushed
        b.write("3")
        content = open(self.test_fp, "r").readlines()
        self.assertEquals(content, ["123"])