Пример #1
0
 def test_get_root_dir_entries_fat16(self, testfs_fat_stable1):
     with open(testfs_fat_stable1[1], 'rb') as img_stream:
         fatfs = fat_16.FAT16(img_stream)
         counter = 0
         for entry in fatfs.get_root_dir_entries():
             assert entry.get_name() == self.expected_entries[counter]
             counter += 1
Пример #2
0
 def test_follow_cluster_fat16(self, testfs_fat_stable1):
     with open(testfs_fat_stable1[1], 'rb') as img_stream:
         fatfs = fat_16.FAT16(img_stream)
         result = fatfs.follow_cluster(4)
         assert result == [4, 5, 6, 7]
         with pytest.raises(Exception):
             result = fatfs.follow_cluster(50)
Пример #3
0
 def test_parse_predata_fat16(self, testfs_fat_stable1):
     """ Test if parsing the predata region for FAT16 works """
     with open(testfs_fat_stable1[1], 'rb') as img_stream:
         fatfs = fat_16.FAT16(img_stream)
         assert fatfs.pre.sector_size == 512
         assert fatfs.pre.sectors_per_cluster == 4
         assert fatfs.pre.reserved_sector_count == 4
         assert fatfs.pre.fat_count == 2
         assert fatfs.pre.rootdir_entry_count == 512
         assert fatfs.pre.sectors_per_fat == 52
Пример #4
0
 def test_get_cluster_value_fat16(self, testfs_fat_stable1):
     with open(testfs_fat_stable1[1], 'rb') as img_stream:
         fatfs = fat_16.FAT16(img_stream)
         assert fatfs.get_cluster_value(0) == 'last_cluster'
         assert fatfs.get_cluster_value(1) == 'last_cluster'
         assert fatfs.get_cluster_value(2) == 'free_cluster'
         assert fatfs.get_cluster_value(3) == 'last_cluster'
         assert fatfs.get_cluster_value(4) == 5
         assert fatfs.get_cluster_value(5) == 6
         assert fatfs.get_cluster_value(6) == 7
         assert fatfs.get_cluster_value(7) == 'last_cluster'
Пример #5
0
 def test_write_exceptions(self, testfs_fat_stable1):
     with open(testfs_fat_stable1[1], 'rb+') as img_stream:
         fatfs = fat_16.FAT16(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, 0xfff7)
Пример #6
0
 def test_cluster_to_stream_fat16(self, testfs_fat_stable1):
     with open(testfs_fat_stable1[1], 'rb') as img_stream:
         fatfs = fat_16.FAT16(img_stream)
         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(7, mem)
             mem.seek(0)
             result = mem.read()
             expected = b'1' * 1856 + b'\n' + b'\x00' * 190 + b'\x00'
             assert result == expected
Пример #7
0
 def test_write_fat_entry_fat16(self, testfs_fat_stable1):
     with open(testfs_fat_stable1[1], 'rb+') as img_stream:
         fatfs = fat_16.FAT16(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)
Пример #8
0
 def test_get_free_cluster_fat16(self, testfs_fat_stable1):
     with open(testfs_fat_stable1[1], 'rb') as img_stream:
         fatfs = fat_16.FAT16(img_stream)
         result = fatfs.get_free_cluster()
         assert result == 17