def test_read_slack(self, testfs_fat_stable1): """ Test if reading content of slackspace in a simple case works """ for img_path in testfs_fat_stable1: with open(img_path, 'rb+') as img_stream: # create FileSlack object fatfs = FileSlack(img_stream) teststring = "This is a simple write test." # write content that we want to read with io.BytesIO() as mem: mem.write(teststring.encode('utf-8')) mem.seek(0) with io.BufferedReader(mem) as reader: write_res = fatfs.write(reader, ['another']) # read content we wrote and compare result with # our initial test message with io.BytesIO() as mem: fatfs.read(mem, write_res) mem.seek(0) result = mem.read() assert result.decode('utf-8') == teststring
def test_clear_slack(self, testfs_fat_stable1): """ Test if clearing slackspace of a file works """ for img_path in testfs_fat_stable1: with open(img_path, 'rb+') as img_stream: # create FileSlack object fatfs = FileSlack(img_stream) teststring = "This is a simple write test." # write content that we want to clear with io.BytesIO() as mem: mem.write(teststring.encode('utf-8')) mem.seek(0) with io.BufferedReader(mem) as reader: write_res = fatfs.write(reader, ['another']) fatfs.clear(write_res) # clear content we wrote, then read the cleared part again. # As it should be overwritten we expect a stream of \x00 with io.BytesIO() as mem: fatfs.read(mem, write_res) mem.seek(0) result = mem.read() expected = len(teststring.encode('utf-8')) * b'\x00' assert result == expected