def test_get_root_dir_entries_fat32(self, testfs_fat_stable1): with open(testfs_fat_stable1[2], 'rb') as img_stream: fatfs = fat_32.FAT32(img_stream) counter = 0 for entry in fatfs.get_root_dir_entries(): assert entry.get_name() == self.expected_entries[counter] counter += 1
def test_follow_cluster_fat32(self, testfs_fat_stable1): with open(testfs_fat_stable1[2], 'rb') as img_stream: fatfs = fat_32.FAT32(img_stream) result = fatfs.follow_cluster(4) assert result == [4, 5] with pytest.raises(Exception): result = fatfs.follow_cluster(50)
def test_get_cluster_value_fat32(self, testfs_fat_stable1): with open(testfs_fat_stable1[2], 'rb') as img_stream: fatfs = fat_32.FAT32(img_stream) assert fatfs.get_cluster_value(0) == 'last_cluster' assert fatfs.get_cluster_value(1) == 'last_cluster' assert fatfs.get_cluster_value(2) == 'last_cluster' assert fatfs.get_cluster_value(3) == 'last_cluster' assert fatfs.get_cluster_value(4) == 5 assert fatfs.get_cluster_value(5) == 'last_cluster' assert fatfs.get_cluster_value(6) == 7 assert fatfs.get_cluster_value(7) == 'last_cluster'
def test_write_exceptions(self, testfs_fat_stable1): with open(testfs_fat_stable1[2], 'rb+') as img_stream: fatfs = fat_32.FAT32(img_stream) with pytest.raises(AttributeError): fatfs.write_fat_entry(-1, 15) with pytest.raises(AttributeError): fatfs.write_fat_entry(fatfs.entries_per_fat, 15) with pytest.raises(AssertionError): fatfs.write_fat_entry(2, 0) with pytest.raises(AssertionError): fatfs.write_fat_entry(2, 0xffffff7)
def test_cluster_to_stream_fat32(self, testfs_fat_stable1): with open(testfs_fat_stable1[2], 'rb') as img_stream: fatfs = fat_32.FAT32(img_stream) result = fatfs.get_free_cluster() with io.BytesIO() as mem: # here we take the last cluster of 'long_file.txt' # as it contains chars and empty space fatfs.cluster_to_stream(5, mem) mem.seek(0) result = mem.read() expected = b'1' * 3904 + b'\n' + b'\x00' * 191 assert result == expected
def test_write_fat_entry_fat32(self, testfs_fat_stable1): with open(testfs_fat_stable1[2], 'rb+') as img_stream: fatfs = fat_32.FAT32(img_stream) actual_value = fatfs.get_cluster_value(4) value_above = fatfs.get_cluster_value(3) value_below = fatfs.get_cluster_value(5) expected = 19 fatfs.write_fat_entry(4, expected) result = fatfs.get_cluster_value(4) assert result == expected # Test that we didn't damage cluster enties beside our own value_above_now = fatfs.get_cluster_value(3) value_below_now = fatfs.get_cluster_value(5) assert value_above_now == value_above assert value_below_now == value_below fatfs.write_fat_entry(4, actual_value)
def test_parse_predata_fat32(self, testfs_fat_stable1): """ Test if parsing the predata region for FAT32 works """ with open(testfs_fat_stable1[2], 'rb') as img_stream: fatfs = fat_32.FAT32(img_stream) assert fatfs.pre.sector_size == 512 assert fatfs.pre.sectors_per_cluster == 8 assert fatfs.pre.reserved_sector_count == 32 assert fatfs.pre.fat_count == 2 assert fatfs.pre.sectors_per_fat == 544 or \ fatfs.pre.sectors_per_fat == 537 assert fatfs.pre.free_data_cluster_count == 68599 or \ fatfs.pre.free_data_cluster_count == 68600 assert fatfs.pre.last_allocated_data_cluster == 12 assert fatfs.pre.flags.active_fat == 0 assert not fatfs.pre.flags.mirrored assert fatfs.pre.fsinfo_sector == 1 assert fatfs.pre.bootsector_copy_sector == 6
def test_get_free_cluster_fat32(self, testfs_fat_stable1): with open(testfs_fat_stable1[2], 'rb') as img_stream: fatfs = fat_32.FAT32(img_stream) result = fatfs.get_free_cluster() assert result == 13