Beispiel #1
0
 def test_write_file(self, testfs_fat_stable1):
     """" Test writing a file into root directory """
     for img_path in testfs_fat_stable1:
         with open(img_path, 'rb+') as img_stream:
             # create FileSlack object
             fatfs = FileSlack(img_stream)
             # setup raw stream and write testmessage
             with io.BytesIO() as mem:
                 teststring = "This is a simple write test."
                 mem.write(teststring.encode('utf-8'))
                 mem.seek(0)
                 # write testmessage to disk
                 with io.BufferedReader(mem) as reader:
                     result = fatfs.write(reader, ['another'])
                     assert result.clusters, [(3, 512 == 28)]
                     with pytest.raises(IOError):
                         mem.seek(0)
                         fatfs.write(reader, ['no_free_slack.txt'])
Beispiel #2
0
 def test_write_file_in_subdir(self, testfs_fat_stable1):
     """ Test writing a file into a subdirectory """
     # only testing fat12 as resulting cluster_id of different fat
     # versions differs
     img_path = testfs_fat_stable1[0]
     with open(img_path, 'rb+') as img_stream:
         # create FileSlack object
         fatfs = FileSlack(img_stream)
         # setup raw stream and write testmessage
         with io.BytesIO() as mem:
             teststring = "This is a simple write test."
             mem.write(teststring.encode('utf-8'))
             mem.seek(0)
             # write testmessage to disk
             with io.BufferedReader(mem) as reader:
                 result = fatfs.write(
                     reader, ['onedirectory/afileinadirectory.txt'])
                 assert result.clusters, [(13, 512 == 28)]
Beispiel #3
0
 def test_write_file_autoexpand_subdir(self, testfs_fat_stable1):  # pylint: disable=invalid-name
     """ Test if autoexpansion for directories as input filepath works """
     # only testing fat12 as resulting cluster_id of different fat
     # versions differs
     # if user supplies a directory instead of a file path, all files under
     # this directory will recusively added
     img_path = testfs_fat_stable1[0]
     with open(img_path, 'rb+') as img_stream:
         # create FileSlack object
         fatfs = FileSlack(img_stream)
         # setup raw stream and write testmessage
         with io.BytesIO() as mem:
             teststring = "This is a simple write test." * 100
             mem.write(teststring.encode('utf-8'))
             mem.seek(0)
             # write testmessage to disk
             with io.BufferedReader(mem) as reader:
                 result = fatfs.write(reader, ['onedirectory'])
                 assert result.clusters == [(13, 512, 1536),
                                            (15, 512, 1264)]
Beispiel #4
0
 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
Beispiel #5
0
 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