Example #1
0
    def test_to_read_only_should_return_a_read_only_segment_with_same_bytes(
            self):
        block_size = 64
        segment = ReadWriteSegment(123, block_size=block_size)
        block_bytes = block_size * b'a'
        segment.write_data(block_bytes)
        segment.write_inode(block_bytes, 123)
        read_only = segment.to_read_only()

        self.assertIsInstance(read_only, ReadOnlySegment)
        self.assertEqual(read_only.to_bytes(), segment.to_bytes())
Example #2
0
    def test_to_and_from_bytes(self):
        block_size = 64
        block = b'a' * block_size
        rw_segment = ReadWriteSegment(123, block_size=block_size)
        block_number = rw_segment.write_data(block)
        r_segment = rw_segment.to_read_only()

        serialized = r_segment.to_bytes()
        deserialized = ReadOnlySegment(serialized, 123, block_size=block_size)

        self.assertEqual(
            deserialized.read_block(block_number)[:len(block)], block)
Example #3
0
    def test_read_block_should_return_the_block(self):
        block_size = 64
        block0 = b'x' * block_size
        block1 = b'a' * block_size
        rw_segment = ReadWriteSegment(123, block_size=block_size)
        rw_segment.write_data(block0)
        rw_segment.write_data(block1)
        rw_segment.write_data(block0)

        r_segment = rw_segment.to_read_only()

        self.assertEqual(r_segment.read_block(1), block1)