예제 #1
0
def test_num_committed(passphrase):
    ff = fakefile.FakeFile(size=-1, failure_mode='ENOSPC')
    aestarfile = aestar.AESTarFile(passphrase=passphrase,
                                   fileobj=ff,
                                   bufsize=512)
    aestarfile.add('test_archive_folder/random512')
    assert aestarfile.num_files == 1
    assert aestarfile.num_committed == 0
    aestarfile.add('test_archive_folder/random2048')
    aestarfile.add('test_archive_folder/random512')
    assert aestarfile.num_committed == 1
    aestarfile.purge_pending()
    assert aestarfile.num_committed == 2
    aestarfile.close()
    assert aestarfile.num_committed == 3
예제 #2
0
def test_EOT_close(passphrase):
    ff = fakefile.FakeFile(size=1024, failure_mode='ENOSPC')
    aestarfile = aestar.AESTarFile(passphrase=passphrase,
                                   fileobj=ff,
                                   bufsize=131072)
    aestarfile.add('test_archive_folder/random512')
    assert aestarfile.num_files == 1
    # this should not raise an error because we are still buffering up to 131072 bytes
    aestarfile.add('test_archive_folder/random1024')
    print(aestarfile.pending_files)
    with pytest.raises(IOError) as e_info:
        # adding a larger file should fail
        aestarfile.add('test_archive_folder/random10MB')
    assert e_info.value.errno == errno.ENOSPC
    assert aestarfile.closed is True
예제 #3
0
def test_fakefile_ok_write():
    f = fakefile.FakeFile(size=512)
    f.write(b'a' * 511)
    f.close()
예제 #4
0
def test_tapefile_both_file_and_fileobj():
    ff = fakefile.FakeFile()
    with pytest.raises(ValueError):
        with aestar.TapeFile(file='tapefile.tmp', fileobj=ff) as f:
            f.close()
예제 #5
0
def test_tapefile():
    ff = fakefile.FakeFile(size=1024, failure_mode='WRITE0')
    with aestar.TapeFile(fileobj=ff) as f:
        f.write(b'a' * 1000)
        with pytest.raises(IOError):
            f.write('b' * 512)
예제 #6
0
def test_fakefile_fail_write0():
    f = fakefile.FakeFile(size=512, failure_mode='WRITE0')
    result = f.write(b'a' * 513)
    assert result == 0
    f.close()
예제 #7
0
def test_fakefile_write_return():
    f = fakefile.FakeFile(size=512, failure_mode='ENOSPC')
    result = f.write(b'a' * 256)
    assert result == 256
예제 #8
0
def test_fakefile_fail_enospc():
    f = fakefile.FakeFile(size=512, failure_mode='ENOSPC')
    f.write(b'a' * 256)
    with pytest.raises(IOError):
        f.write(b'a' * 257)
    f.close()