Esempio n. 1
0
    def test_inode_block_numbers_should_return_a_list_of_inode_numbers_and_their_block_numbers(
            self):
        segment = ReadWriteSegment(123)
        inum0 = 111
        inum1 = 999
        segment.write_inode(b'abcd', inum0)
        segment.write_inode(b'abcd', inum1)

        self.assertEqual(segment.inode_block_numbers(), [(inum0, 0),
                                                         (inum1, 1)])
Esempio n. 2
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())
Esempio n. 3
0
    def test_write_inode_returns_the_block_number(self):
        block_size = 64
        segment = ReadWriteSegment(123, block_size=block_size)
        block_bytes = block_size * b'a'

        for expected_block_number in range(5):
            returned_block_number = segment.write_inode(block_bytes, 123)
            self.assertEqual(returned_block_number, expected_block_number)
Esempio n. 4
0
    def test_write_inode_when_bytes_is_a_full_block_does_not_pad_the_block(
            self):
        block_size = 64
        segment = ReadWriteSegment(123, block_size=block_size)
        block_bytes = block_size * b'a'
        block_number = segment.write_inode(block_bytes, 123)

        self.assertEqual(segment.read_block(block_number), block_bytes)
        self.assertEqual(block_number, 0)
Esempio n. 5
0
    def test_write_inode_when_bytes_less_than_block_pads_the_block(self):
        block_size = 64
        segment = ReadWriteSegment(123, block_size=block_size)
        block_bytes = (block_size // 2) * b'a'
        block_number = segment.write_inode(block_bytes, 123)

        padded_block = block_bytes + b'\0' * (block_size - len(block_bytes))

        self.assertEqual(segment.read_block(block_number), padded_block)
        self.assertEqual(block_number, 0)