Exemplo n.º 1
0
def test_file_system_delete():
    """
    Test content being deleted, and removal of size from ancestors
    """

    file_system = FileSystem()

    drive_a = file_system.create('drive', 'a', '')

    folder_a = file_system.create('folder', 'a', 'a')

    text_a = file_system.create('text', 'a', 'a\\a')

    test_string = 'teststring'
    file_system.write_to_file(text_a.path, test_string)

    assert folder_a.size == len(test_string)
    assert drive_a.size == len(test_string)

    file_system.delete(text_a.path)

    assert 'a' not in folder_a.get_names()
    assert folder_a.size == 0
    assert drive_a.size == 0
Exemplo n.º 2
0
def test_file_system_move():
    """
    Test content being moved and sizes being incremented and decremented
    """

    file_system = FileSystem()

    file_system.create('drive', 'a', '')

    folder_b_source = file_system.create('folder', 'b', 'a')

    folder_b_target = file_system.create('folder', 'bb', 'a')

    text_c = file_system.create('text', 'c', 'a\\b')

    test_string = 'teststring'
    file_system.write_to_file(text_c.path, test_string)

    file_system.move(text_c.path, folder_b_target.path)

    assert 'c' not in folder_b_source.get_names()
    assert 'c' in folder_b_target.get_names()
    assert folder_b_source.size == 0
    assert folder_b_target.size == len(test_string)
Exemplo n.º 3
0
def test_file_system_root():
    """
    Test the root to ensure only drives can be added
    """

    file_system = FileSystem()

    with pytest.raises(IllegalFileSystemOperation):
        file_system.create('folder', 'test', 'root')

    with pytest.raises(IllegalFileSystemOperation):
        file_system.create('zip', 'test', 'root')

    with pytest.raises(IllegalFileSystemOperation):
        file_system.create('text', 'test', 'root')

    new_drive = file_system.create('drive', 'test', 'root')

    assert new_drive.entity_type == 'drive'
    assert new_drive.path == 'test'
    assert new_drive.size == 0
Exemplo n.º 4
0
def test_file_system_string():
    """
    Test the file system string method
    """

    file_system = FileSystem()

    file_system.create('drive', 'A', '')
    file_system.create('drive', 'B', '')

    file_system.create('folder', 'stuff1', 'A')
    file_system.create('zip', 'zip1', 'A\\stuff1')
    text_file = file_system.create('text', 'list1', 'A\\stuff1\\zip1')
    file_system.create('folder', 'stuff2', 'A')

    file_system.write_to_file(text_file.path, 'test')

    file_system.create('zip', 'stuff3', 'B')
    file_system.create('folder', 'stuff4', 'B\\stuff3')

    expected_string = 'A 2\nA\\stuff1 2\nA\\stuff1\\zip1 2\nA\\stuff1\\zip1\\list1 4\nA\\stuff2 0\n' \
                      'B 0\nB\\stuff3 0\nB\\stuff3\\stuff4 0'

    assert str(file_system) == expected_string
Exemplo n.º 5
0
def main():
    """
    Demonstrates the FileSystem implementation.
    Executes methods and prints the file system structure after each operation.
    """

    print('\n##############')
    print('# File System')
    print('##############\n')

    print('Package in /file_system\n')

    print('Pytest suite in /tests\n')

    print('###################')
    print('# File System Demo')
    print('###################\n')

    print('1. Creating File System')
    file_system = FileSystem()

    print('2. Adding DriveA to Root')
    file_system.create('drive', 'DriveA', '')
    print('Current File System Structure: \n' + str(file_system))
    print()

    print('3. Adding DriveB to Root')
    file_system.create('drive', 'DriveB', '')
    print('Current File System Structure: \n' + str(file_system))
    print()

    print('4. Adding FolderA to DriveA')
    file_system.create('folder', 'FolderA', 'DriveA')
    print('Current File System Structure: \n' + str(file_system))
    print()

    print('5. Adding FolderB to DriveB')
    folder_b = file_system.create('folder', 'FolderB', 'DriveB')
    print('Current File System Structure: \n' + str(file_system))
    print()

    print('6. Adding FolderC to FolderB')
    file_system.create('folder', 'FolderC', 'DriveB\\FolderB')
    print('Current File System Structure: \n' + str(file_system))
    print()

    print('7. Adding ZipA to DriveA')
    zip_a = file_system.create('zip', 'ZipA', 'DriveA')
    print('Current File System Structure: \n' + str(file_system))
    print()

    print('8. Adding TextA to FolderC')
    text_a = file_system.create('text', 'TextA', 'DriveB\\FolderB\\FolderC')
    print('Current File System Structure: \n' + str(file_system))
    print()

    print('9. Updating TextA Content with \'testabcd\'')
    file_system.write_to_file(text_a.path, 'testabcd')
    print('Current File System Structure: \n' + str(file_system))
    print()

    print('10. Adding TextB to ZipA')
    text_b = file_system.create('text', 'TextB', 'DriveA\\ZipA')
    print('Current File System Structure: \n' + str(file_system))
    print()

    print('11. Updating TextB Content with \'testabcdtestabcd\'')
    file_system.write_to_file(text_b.path, 'testabcdtestabcd')
    print('Current File System Structure: \n' + str(file_system))
    print()

    print('12. Move FolderB into ZipA')
    file_system.move(folder_b.path, zip_a.path)
    print('Current File System Structure: \n' + str(file_system))
    print()