コード例 #1
0
    def test_inplace_addition(self):
        self.buf += 'bar'
        self.assertEquals(self.buf, ReadOnceBuffer('spameggsbar'))

        #inplace addition returns the same object
        self._buf = self.buf
        self.buf += 'foo'
        self.assertIs(self.buf, self._buf)
コード例 #2
0
class ReadOnceBufferTest(unittest.TestCase):
    
    def setUp(self):
        self.buf = ReadOnceBuffer('spameggs')

    def test_identity(self):
        self.assertEquals(self.buf, ReadOnceBuffer('spameggs'))

    def test_addition(self):
        self.assertEquals(self.buf + 'foo', ReadOnceBuffer('spameggsfoo'))

        #addition returns a new object
        self.assertIsNot(self.buf + 'foo', self.buf)

    def test_inplace_addition(self):
        self.buf += 'bar'
        self.assertEquals(self.buf, ReadOnceBuffer('spameggsbar'))

        #inplace addition returns the same object
        self._buf = self.buf
        self.buf += 'foo'
        self.assertIs(self.buf, self._buf)

    def test_raise_out_of_bounds(self):
        self.assertRaises(IndexError, lambda: self.buf[200])

    def test_indexing_deletes(self):
        self.assertEquals(ord('p'), self.buf[1])
        self.assertEquals(ReadOnceBuffer('sameggs'), self.buf)

    def test_slicing_deletes(self):
        self.assertEquals(ReadOnceBuffer('ame'), self.buf[2:5])
        self.assertEquals(ReadOnceBuffer('spggs'), self.buf)

    def test_full_deletion(self):
        self.assertEquals(ReadOnceBuffer('spameggs'), self.buf[:])
        self.assertEquals(ReadOnceBuffer(), self.buf)

    def test_peek_index_doesnt_delete(self):
        self.assertEquals(self.buf.peek(2), ord('a'))
        self.assertEquals(self.buf, ReadOnceBuffer('spameggs'))

    def test_peek_slice_doesnt_delete(self):
        self.assertEquals(self.buf.peek(2, 5), ReadOnceBuffer('ame'))
        self.assertEquals(self.buf, ReadOnceBuffer('spameggs'))
コード例 #3
0
class ReadOnceBufferTest(unittest.TestCase):
    def setUp(self):
        self.buf = ReadOnceBuffer('spameggs')

    def test_identity(self):
        self.assertEquals(self.buf, ReadOnceBuffer('spameggs'))

    def test_addition(self):
        self.assertEquals(self.buf + 'foo', ReadOnceBuffer('spameggsfoo'))

        #addition returns a new object
        self.assertIsNot(self.buf + 'foo', self.buf)

    def test_inplace_addition(self):
        self.buf += 'bar'
        self.assertEquals(self.buf, ReadOnceBuffer('spameggsbar'))

        #inplace addition returns the same object
        self._buf = self.buf
        self.buf += 'foo'
        self.assertIs(self.buf, self._buf)

    def test_raise_out_of_bounds(self):
        self.assertRaises(IndexError, lambda: self.buf[200])

    def test_indexing_deletes(self):
        self.assertEquals(ord('p'), self.buf[1])
        self.assertEquals(ReadOnceBuffer('sameggs'), self.buf)

    def test_slicing_deletes(self):
        self.assertEquals(ReadOnceBuffer('ame'), self.buf[2:5])
        self.assertEquals(ReadOnceBuffer('spggs'), self.buf)

    def test_full_deletion(self):
        self.assertEquals(ReadOnceBuffer('spameggs'), self.buf[:])
        self.assertEquals(ReadOnceBuffer(), self.buf)

    def test_peek_index_doesnt_delete(self):
        self.assertEquals(self.buf.peek(2), ord('a'))
        self.assertEquals(self.buf, ReadOnceBuffer('spameggs'))

    def test_peek_slice_doesnt_delete(self):
        self.assertEquals(self.buf.peek(2, 5), ReadOnceBuffer('ame'))
        self.assertEquals(self.buf, ReadOnceBuffer('spameggs'))
コード例 #4
0
 def setUp(self):
     self.buf = ReadOnceBuffer('spameggs')
コード例 #5
0
 def test_identity(self):
     self.assertEquals(self.buf, ReadOnceBuffer('spameggs'))
コード例 #6
0
 def setUp(self):
     self.buf = ReadOnceBuffer('spameggs')
コード例 #7
0
 def test_peek_slice_doesnt_delete(self):
     self.assertEquals(self.buf.peek(2, 5), ReadOnceBuffer('ame'))
     self.assertEquals(self.buf, ReadOnceBuffer('spameggs'))
コード例 #8
0
 def test_peek_index_doesnt_delete(self):
     self.assertEquals(self.buf.peek(2), ord('a'))
     self.assertEquals(self.buf, ReadOnceBuffer('spameggs'))
コード例 #9
0
 def test_full_deletion(self):
     self.assertEquals(ReadOnceBuffer('spameggs'), self.buf[:])
     self.assertEquals(ReadOnceBuffer(), self.buf)
コード例 #10
0
 def test_slicing_deletes(self):
     self.assertEquals(ReadOnceBuffer('ame'), self.buf[2:5])
     self.assertEquals(ReadOnceBuffer('spggs'), self.buf)
コード例 #11
0
 def test_indexing_deletes(self):
     self.assertEquals(ord('p'), self.buf[1])
     self.assertEquals(ReadOnceBuffer('sameggs'), self.buf)
コード例 #12
0
    def test_addition(self):
        self.assertEquals(self.buf + 'foo', ReadOnceBuffer('spameggsfoo'))

        #addition returns a new object
        self.assertIsNot(self.buf + 'foo', self.buf)