示例#1
0
    def test_basics(self):
        a = ArrayStream()
        self.assertEmpty(a)
        self.assertContentsMatch(a, [])

        a.flush()
        self.assertEmpty(a)
        self.assertContentsMatch(a, [])

        a.write("foo")
        a.write("bar")
        self.assertNotEmpty(a)
        self.assertContentsMatch(a, ["foo", "bar"])

        a.flush()
        self.assertNotEmpty(a)
        self.assertContentsMatch(a, ["foo", "bar"])

        a.reset()
        self.assertEmpty(a)
        self.assertContentsMatch(a, [])

        self.assertEquals(str(a), "<ArrayStream: []>")

        a.write("foo")
        self.assertNotEmpty(a)
        self.assertContentsMatch(a, ["foo"])
        self.assertEquals(str(a), "<ArrayStream: ['foo']>")
    def test_basics(self):
        a = ArrayStream()
        self.assertEmpty(a)
        self.assertContentsMatch(a, [])

        a.flush()
        self.assertEmpty(a)
        self.assertContentsMatch(a, [])

        a.write("foo")
        a.write("bar")
        self.assertNotEmpty(a)
        self.assertContentsMatch(a, ["foo", "bar"])

        a.flush()
        self.assertNotEmpty(a)
        self.assertContentsMatch(a, ["foo", "bar"])

        a.reset()
        self.assertEmpty(a)
        self.assertContentsMatch(a, [])

        self.assertEquals(str(a), "<ArrayStream: []>")

        a.write("foo")
        self.assertNotEmpty(a)
        self.assertContentsMatch(a, ["foo"])
        self.assertEquals(str(a), "<ArrayStream: ['foo']>")
    def test_regular(self):
        a = ArrayStream()
        m = metered_stream.MeteredStream(verbose=False, stream=a)
        self.assertTrue(a.empty())

        # basic test - note that the flush() is a no-op, but we include it
        # for coverage.
        m.write("foo")
        m.flush()
        exp = ['foo']
        self.assertEquals(a.get(), exp)

        # now check that a second write() does not overwrite the first.
        m.write("bar")
        exp.append('bar')
        self.assertEquals(a.get(), exp)

        m.update("batter")
        exp.append('batter')
        self.assertEquals(a.get(), exp)

        # The next update() should overwrite the laste update() but not the
        # other text. Note that the cursor is effectively positioned at the
        # end of 'foo', even though we had to erase three more characters.
        m.update("foo")
        exp.append('\b\b\b\b\b\b      \b\b\b\b\b\b')
        exp.append('foo')
        self.assertEquals(a.get(), exp)

        m.progress("progress")
        exp.append('\b\b\b   \b\b\b')
        exp.append('progress')
        self.assertEquals(a.get(), exp)

        # now check that a write() does overwrite the progress bar
        m.write("foo")
        exp.append('\b\b\b\b\b\b\b\b        \b\b\b\b\b\b\b\b')
        exp.append('foo')
        self.assertEquals(a.get(), exp)

        # Now test that we only back up to the most recent newline.

        # Note also that we do not back up to erase the most recent write(),
        # i.e., write()s do not get erased.
        a.reset()
        m.update("foo\nbar")
        m.update("baz")
        self.assertEquals(a.get(), ['foo\nbar', '\b\b\b   \b\b\b', 'baz'])
    def test_regular(self):
        a = ArrayStream()
        m = metered_stream.MeteredStream(verbose=False, stream=a)
        self.assertTrue(a.empty())

        # basic test - note that the flush() is a no-op, but we include it
        # for coverage.
        m.write("foo")
        m.flush()
        exp = ['foo']
        self.assertEquals(a.get(), exp)

        # now check that a second write() does not overwrite the first.
        m.write("bar")
        exp.append('bar')
        self.assertEquals(a.get(), exp)

        m.update("batter")
        exp.append('batter')
        self.assertEquals(a.get(), exp)

        # The next update() should overwrite the laste update() but not the
        # other text. Note that the cursor is effectively positioned at the
        # end of 'foo', even though we had to erase three more characters.
        m.update("foo")
        exp.append('\b\b\b\b\b\b      \b\b\b\b\b\b')
        exp.append('foo')
        self.assertEquals(a.get(), exp)

        m.progress("progress")
        exp.append('\b\b\b   \b\b\b')
        exp.append('progress')
        self.assertEquals(a.get(), exp)

        # now check that a write() does overwrite the progress bar
        m.write("foo")
        exp.append('\b\b\b\b\b\b\b\b        \b\b\b\b\b\b\b\b')
        exp.append('foo')
        self.assertEquals(a.get(), exp)

        # Now test that we only back up to the most recent newline.

        # Note also that we do not back up to erase the most recent write(),
        # i.e., write()s do not get erased.
        a.reset()
        m.update("foo\nbar")
        m.update("baz")
        self.assertEquals(a.get(), ['foo\nbar', '\b\b\b   \b\b\b', 'baz'])