Ejemplo n.º 1
0
 def setUp(self):
     DefaultTestFixture.setUp(self)
     self._buffer = StringIO.StringIO()
     self._circular = CircularBuffer(self._buffer,10)
     return
Ejemplo n.º 2
0
 def setUp(self):
     DefaultTestFixture.setUp(self)
     self._buffer = StringIO.StringIO()
     self._circular = CircularBuffer(self._buffer, 10)
     return
Ejemplo n.º 3
0
class TestCase(DefaultTestFixture):
    ##
    # Sets up self.log who is configured to have columns:
    # timestamp, reverse, c2, c3, c4 for seqs 0-19, 40-59, 80-99, 120-139 
    # and columns timestamp, reverse, c2, c3 for seqs: 20-39, 60-79, 100-119,
    # 140-159
    def setUp(self):
        DefaultTestFixture.setUp(self)
        self._buffer = StringIO.StringIO()
        self._circular = CircularBuffer(self._buffer,10)
        return
    def tearDown(self):
        try:
            self._circular.close()
            del(self._circular)
        finally:
            DefaultTestFixture.tearDown(self)
        return
    def test_initialize(self):
        self._circular.initialize('\x00')
        self.failUnless(self._circular.tell() == 0,'Initialize failed to ' +
                        'return buffer to 0.')
        self.failUnless(len(self._circular) == 0, 'Circular failed to ' + 
                        'report correct buffer length')
    def test_read(self):
        data = ''
        for i in range(0,10):
            data += str(i)
        self._circular.write(data)
        self._circular.seek(0)
        self.failUnless(self._circular.read(1) == '0',
                        'Failed to read first byte')
        self.failUnless(self._circular.read(9) == data[1:], 
                        'Failed to read the remaining data')
        self.failUnless(self._circular.read(1) == '0',
                        'Failed to wrap correctly')
        self.failUnless(self._circular.read(10) == data[1:]+'0',
                       'Failed to wrap correctly on read that carried over')
        self.failUnless(len(self._circular.read(11)) == 10, 
                         'Returned more than length data')
    def test_write(self):
        self._circular.write('shane')
        self.failUnless(self._circular.tell() == 5,'Did not correctly ' + 
                        'return seek location after writing')
        self._circular.write('c'*10)
        self.failUnless(self._circular.tell() == 10, 
                        'Did not wrap correctly at end')
        self.failUnless(self._circular.read(10) == 'c'*10,
                        'Did not return correct data after write')
        self.failUnless(self._circular.tell() == 10, 'Did not wrap after read')
        self._circular.seek(10)
        self._circular.write('a')
        self._circular.seek(0)
        self.failUnless(self._circular.read(1) == 'a', 
                        'Did not write to beginning when at end')
        self.failUnless(len(self._circular) == 10, 
                        'Reported incorrect length')
Ejemplo n.º 4
0
class TestCase(DefaultTestFixture):
    ##
    # Sets up self.log who is configured to have columns:
    # timestamp, reverse, c2, c3, c4 for seqs 0-19, 40-59, 80-99, 120-139
    # and columns timestamp, reverse, c2, c3 for seqs: 20-39, 60-79, 100-119,
    # 140-159
    def setUp(self):
        DefaultTestFixture.setUp(self)
        self._buffer = StringIO.StringIO()
        self._circular = CircularBuffer(self._buffer, 10)
        return

    def tearDown(self):
        try:
            self._circular.close()
            del (self._circular)
        finally:
            DefaultTestFixture.tearDown(self)
        return

    def test_initialize(self):
        self._circular.initialize('\x00')
        self.failUnless(self._circular.tell() == 0,
                        'Initialize failed to ' + 'return buffer to 0.')
        self.failUnless(
            len(self._circular) == 0,
            'Circular failed to ' + 'report correct buffer length')

    def test_read(self):
        data = ''
        for i in range(0, 10):
            data += str(i)
        self._circular.write(data)
        self._circular.seek(0)
        self.failUnless(
            self._circular.read(1) == '0', 'Failed to read first byte')
        self.failUnless(
            self._circular.read(9) == data[1:],
            'Failed to read the remaining data')
        self.failUnless(
            self._circular.read(1) == '0', 'Failed to wrap correctly')
        self.failUnless(
            self._circular.read(10) == data[1:] + '0',
            'Failed to wrap correctly on read that carried over')
        self.failUnless(
            len(self._circular.read(11)) == 10,
            'Returned more than length data')

    def test_write(self):
        self._circular.write('shane')
        self.failUnless(
            self._circular.tell() == 5,
            'Did not correctly ' + 'return seek location after writing')
        self._circular.write('c' * 10)
        self.failUnless(self._circular.tell() == 10,
                        'Did not wrap correctly at end')
        self.failUnless(
            self._circular.read(10) == 'c' * 10,
            'Did not return correct data after write')
        self.failUnless(self._circular.tell() == 10, 'Did not wrap after read')
        self._circular.seek(10)
        self._circular.write('a')
        self._circular.seek(0)
        self.failUnless(
            self._circular.read(1) == 'a',
            'Did not write to beginning when at end')
        self.failUnless(len(self._circular) == 10, 'Reported incorrect length')