Exemplo n.º 1
0
def test_move_folder():
    """
    Test moving an entire folder
    Initial state:

        Drive1
        |_Folder1
          |_File1
        |_Zip1

    Final state:

        Drive1
        |_Zip1
          |_Folder1
            |_File1
    """
    drive = memfs.create('drive', 'Drive1')
    folder1 = memfs.create('folder', 'Folder1', drive.path)
    file1 = memfs.create('file', 'File1', folder1.path)
    zip1 = memfs.create('zip', 'Zip1', drive.path)
    assert len(folder1.children) == 1
    assert len(zip1.children) == 0
    memfs.move(folder1.path, "{}\\{}".format(zip1.path, folder1.name))
    assert len(folder1.children) == 1
    assert len(zip1.children) == 1
    assert folder1.parent.name == zip1.name
    assert file1.parent.name == folder1.name
Exemplo n.º 2
0
def test_move_file_to_file():
    """
    Files must be leaf nodes and cannot have items moved under them
    """
    drive1 = memfs.create('drive', 'Drive1')
    file1 = memfs.create('file', ' File1', drive1.path)
    file2 = memfs.create('file', 'File2', drive1.path)
    try:
        memfs.move(file1.path, '{}\\{}'.format(file1.path, file2.name))
        assert True == False  # Should not get here
    except Exception as e:
        assert type(e) == IllegalFileSystemOperation
Exemplo n.º 3
0
def test_move_file_to_root():
    """
    Files cannot be moved to the root
    Should raise an exception
    """
    drive1 = memfs.create('drive', 'Drive1')
    file1 = memfs.create('file', ' File1', drive1.path)
    try:
        memfs.move(file1.path, file1.name)
        assert True == False  # Should not get here
    except Exception as e:
        assert type(e) == IllegalFileSystemOperation
Exemplo n.º 4
0
def test_move_drive():
    """
    Drives cannot be moved (they must be root entities)
    Should raise an exception
    """
    drive1 = memfs.create('drive', 'Drive1')
    drive2 = memfs.create('drive', 'Drive2')
    try:
        memfs.move(drive2.path, "{}\\{}".format(drive1.path, drive2.name))
        assert True == False  # Should not get here
    except Exception as e:
        assert type(e) == IllegalFileSystemOperation
Exemplo n.º 5
0
def test_move_already_exists_file():
    """
    You can't move a file to a path where one already exists (no overwrites)
    """
    drive = memfs.create('drive', 'Drive1')
    file1 = memfs.create('file', 'File1', drive.path)
    file2 = memfs.create('file', 'File2', drive.path)
    try:
        memfs.move(file1.path, file2.path)
        assert True == False  # Should not get here
    except Exception as e:
        assert type(e) == PathAlreadyExistsException
Exemplo n.º 6
0
def test_move_non_existent_file():
    """
    Trying to move a non-existent source file should fail with an error
    """
    drive = memfs.create('drive', 'Drive1')
    folder1 = memfs.create('folder', 'Folder1', drive.path)
    try:
        memfs.move("{}\\{}".format(drive.path, "FakeFile"),
                   "{}\\{}".format(drive.path, folder1.name))
        assert True == False  # Should not get here
    except Exception as e:
        assert type(e) == PathNotFoundException