Ejemplo n.º 1
0
def test_rename(tmppath):
    """Test rename."""
    fs = XRootDPyFS(mkurl(tmppath))

    pytest.raises(DestinationExistsError, fs.rename, "data/testa.txt",
                  "multiline.txt")
    pytest.raises(DestinationExistsError, fs.rename, "data/testa.txt",
                  "afolder/afile.txt")
    pytest.raises(DestinationExistsError, fs.rename, "data/afolder", "bfolder")
    pytest.raises(DestinationExistsError, fs.rename, "data/afolder",
                  "bfolder/bfile.txt")

    pytest.raises(ResourceNotFoundError, fs.rename, "data/invalid.txt",
                  "afolder/afile.txt")

    assert fs.exists("data/testa.txt") and not fs.exists("data/testb.txt")
    fs.rename("data/testa.txt", "testb.txt")
    assert fs.exists("data/testb.txt") and not fs.exists("data/testa.txt")

    assert fs.exists("data/afolder/") and not fs.exists("data/cfolder/")
    fs.rename("data/afolder/", "cfolder")
    assert fs.exists("data/cfolder") and not fs.exists("data/afolder")

    fs.rename("data/cfolder/", "a/b/c/test")
    assert fs.exists("data/a/b/c/test/")
Ejemplo n.º 2
0
def test_rename(tmppath):
    """Test rename."""
    fs = XRootDPyFS(mkurl(tmppath))

    pytest.raises(
        DestinationExistsError, fs.rename, "data/testa.txt", "multiline.txt")
    pytest.raises(
        DestinationExistsError, fs.rename, "data/testa.txt",
        "afolder/afile.txt")
    pytest.raises(
        DestinationExistsError, fs.rename, "data/afolder", "bfolder")
    pytest.raises(
        DestinationExistsError, fs.rename, "data/afolder", "bfolder/bfile.txt")

    pytest.raises(
        ResourceNotFoundError, fs.rename, "data/invalid.txt",
        "afolder/afile.txt")

    assert fs.exists("data/testa.txt") and not fs.exists("data/testb.txt")
    fs.rename("data/testa.txt", "testb.txt")
    assert fs.exists("data/testb.txt") and not fs.exists("data/testa.txt")

    assert fs.exists("data/afolder/") and not fs.exists("data/cfolder/")
    fs.rename("data/afolder/", "cfolder")
    assert fs.exists("data/cfolder") and not fs.exists("data/afolder")

    fs.rename("data/cfolder/", "a/b/c/test")
    assert fs.exists("data/a/b/c/test/")
Ejemplo n.º 3
0
def test_unicode_paths(tmppath):
    """Test creation of unicode paths."""
    fs = XRootDPyFS(mkurl(tmppath))
    d = u'\xe6\xf8\xe5'
    assert not fs.exists(d)
    assert fs.makedir(d)
    assert fs.exists(d)
    d = '\xc3\xb8\xc3\xa5\xc3\xa6'
    assert not fs.exists(d)
    assert fs.makedir(d)
    assert fs.exists(d)
Ejemplo n.º 4
0
def test_unicode_paths(tmppath):
    """Test creation of unicode paths."""
    fs = XRootDPyFS(mkurl(tmppath))
    d = u'\xe6\xf8\xe5'
    assert not fs.exists(d)
    assert fs.makedir(d)
    assert fs.exists(d)
    d = '\xc3\xb8\xc3\xa5\xc3\xa6'
    assert not fs.exists(d)
    assert fs.makedir(d)
    assert fs.exists(d)
Ejemplo n.º 5
0
def test_remove_dir(tmppath):
    """Test removedir."""
    fs = XRootDPyFS(mkurl(tmppath))

    # Remove non-empty directory
    pytest.raises(DirectoryNotEmptyError, fs.removedir, "data/bfolder/")

    # Use of recursive parameter
    pytest.raises(UnsupportedError,
                  fs.removedir,
                  "data/bfolder/",
                  recursive=True)

    # Remove file
    pytest.raises(ResourceInvalidError, fs.removedir, "data/testa.txt")

    # Remove empty directory
    fs.makedir("data/tmp")
    assert fs.removedir("data/tmp") and not fs.exists("data/tmp")

    # Remove non-empty directory
    assert fs.removedir("data/bfolder/", force=True)
    assert fs.removedir("data/", force=True)
Ejemplo n.º 6
0
def test_remove_dir(tmppath):
    """Test removedir."""
    fs = XRootDPyFS(mkurl(tmppath))

    # Remove non-empty directory
    pytest.raises(
        DirectoryNotEmptyError, fs.removedir, "data/bfolder/")

    # Use of recursive parameter
    pytest.raises(
        UnsupportedError, fs.removedir, "data/bfolder/", recursive=True)

    # Remove file
    pytest.raises(
        ResourceInvalidError, fs.removedir, "data/testa.txt")

    # Remove empty directory
    fs.makedir("data/tmp")
    assert fs.removedir("data/tmp") and not fs.exists("data/tmp")

    # Remove non-empty directory
    assert fs.removedir("data/bfolder/", force=True)
    assert fs.removedir("data/", force=True)
Ejemplo n.º 7
0
def copydir_good(tmppath, parallel):
    """Test copy directory."""
    fs = XRootDPyFS(mkurl(tmppath))

    src_exists = "data/afolder/"
    dst_exists = "data/multiline.txt"
    dst_new = "data/ok.txt"
    dst_folder_exists = "data/bfolder/"
    dst_folder_new = "data/anothernewfolder/"

    assert fs.isdir(src_exists)
    assert fs.exists(dst_exists)
    assert not fs.exists(dst_new)
    assert fs.exists(dst_folder_exists)
    assert not fs.exists(dst_folder_new)

    fs.copydir(src_exists, dst_new, parallel=parallel)
    assert fs.exists(src_exists) and fs.exists(dst_new)

    fs.copydir(src_exists, dst_folder_new, parallel=parallel)
    assert fs.exists(src_exists) and fs.exists(dst_folder_new)

    fs.copydir(src_exists, dst_exists, overwrite=True, parallel=parallel)
    assert fs.exists(src_exists) and fs.exists(dst_exists)
    assert fs.isdir(dst_exists)

    fs.copydir(src_exists,
               dst_folder_exists,
               overwrite=True,
               parallel=parallel)
    assert fs.exists(src_exists) and fs.exists(dst_folder_exists)
    assert fs.isdir(dst_folder_exists)
Ejemplo n.º 8
0
def test_copy_good(tmppath):
    """Test move file."""
    fs = XRootDPyFS(mkurl(tmppath))

    src_exists = "data/testa.txt"
    dst_exists = "data/multiline.txt"
    dst_new = "data/ok.txt"
    dst_folder_exists = "data/bfolder/"
    dst_folder_new = "data/anothernewfolder/"
    content = _get_content(fs, src_exists)

    assert fs.exists(dst_exists)
    assert not fs.exists(dst_new)
    assert fs.exists(dst_folder_exists)
    assert not fs.exists(dst_folder_new)

    fs.copy(src_exists, dst_new)
    assert fs.exists(src_exists) and fs.exists(dst_new)

    fs.copy(src_exists, dst_folder_new)
    assert fs.exists(src_exists) and fs.exists(dst_folder_new)

    fs.copy(src_exists, dst_exists, overwrite=True)
    assert fs.exists(src_exists) and fs.exists(dst_exists)
    assert content == _get_content(fs, dst_exists)

    fs.copy(src_exists, dst_folder_exists, overwrite=True)
    assert fs.exists(src_exists) and fs.exists(dst_folder_exists)
    assert content == _get_content(fs, dst_folder_exists)
Ejemplo n.º 9
0
def test_movedir_good(tmppath):
    """Test move file."""
    fs = XRootDPyFS(mkurl(tmppath))

    src_exists = "data/afolder/"
    dst_exists = "data/multiline.txt"
    dst_new = "data/ok.txt"
    dst_folder_exists = "data/bfolder/"
    dst_folder_new = "data/anothernewfolder/"

    assert fs.isdir(src_exists)
    assert fs.exists(dst_exists)
    assert not fs.exists(dst_new)
    assert fs.exists(dst_folder_exists)
    assert not fs.exists(dst_folder_new)

    fs.movedir(src_exists, dst_new)
    assert not fs.exists(src_exists) and fs.exists(dst_new)

    fs.movedir(dst_new, src_exists)
    fs.movedir(src_exists, dst_folder_new)
    assert not fs.exists(src_exists) and fs.exists(dst_folder_new)

    fs.movedir(dst_folder_new, src_exists)
    fs.movedir(src_exists, dst_exists, overwrite=True)
    assert not fs.exists(src_exists) and fs.exists(dst_exists)
    assert fs.isdir(dst_exists)

    fs.movedir(dst_exists, src_exists)
    fs.movedir(src_exists, dst_folder_exists, overwrite=True)
    assert not fs.exists(src_exists) and fs.exists(dst_folder_exists)
    assert fs.isdir(dst_folder_exists)
Ejemplo n.º 10
0
def test_movedir_good(tmppath):
    """Test move file."""
    fs = XRootDPyFS(mkurl(tmppath))

    src_exists = "data/afolder/"
    dst_exists = "data/multiline.txt"
    dst_new = "data/ok.txt"
    dst_folder_exists = "data/bfolder/"
    dst_folder_new = "data/anothernewfolder/"

    assert fs.isdir(src_exists)
    assert fs.exists(dst_exists)
    assert not fs.exists(dst_new)
    assert fs.exists(dst_folder_exists)
    assert not fs.exists(dst_folder_new)

    # Move to new folder (without trailing slash).
    fs.movedir(src_exists, dst_new)
    assert not fs.exists(src_exists) and fs.exists(dst_new)

    fs.movedir(dst_new, src_exists)  # reset
    # Move to new folder (with trailing slash).
    fs.movedir(src_exists, dst_folder_new)
    assert not fs.exists(src_exists) and fs.exists(dst_folder_new)

    fs.movedir(dst_folder_new, src_exists)  # reset
    # Move to existing filer with overwrite (i.e. will remove destination)
    fs.movedir(src_exists, dst_exists, overwrite=True)
    assert not fs.exists(src_exists) and fs.exists(dst_exists)
    assert fs.isdir(dst_exists)

    fs.movedir(dst_exists, src_exists)  # reset
    # Move to existing folder with overwrite (i.e. will remove destination)
    fs.movedir(src_exists, dst_folder_exists, overwrite=True)
    assert not fs.exists(src_exists) and fs.exists(dst_folder_exists)
    assert fs.isdir(dst_folder_exists)
Ejemplo n.º 11
0
def copydir_good(tmppath, parallel):
    """Test copy directory."""
    fs = XRootDPyFS(mkurl(tmppath))

    src_exists = "data/afolder/"
    dst_exists = "data/multiline.txt"
    dst_new = "data/ok.txt"
    dst_folder_exists = "data/bfolder/"
    dst_folder_new = "data/anothernewfolder/"

    assert fs.isdir(src_exists)
    assert fs.exists(dst_exists)
    assert not fs.exists(dst_new)
    assert fs.exists(dst_folder_exists)
    assert not fs.exists(dst_folder_new)

    fs.copydir(src_exists, dst_new, parallel=parallel)
    assert fs.exists(src_exists) and fs.exists(dst_new)

    fs.copydir(src_exists, dst_folder_new, parallel=parallel)
    assert fs.exists(src_exists) and fs.exists(dst_folder_new)

    fs.copydir(src_exists, dst_exists, overwrite=True, parallel=parallel)
    assert fs.exists(src_exists) and fs.exists(dst_exists)
    assert fs.isdir(dst_exists)

    fs.copydir(
        src_exists, dst_folder_exists, overwrite=True, parallel=parallel)
    assert fs.exists(src_exists) and fs.exists(dst_folder_exists)
    assert fs.isdir(dst_folder_exists)
Ejemplo n.º 12
0
def test_copy_good(tmppath):
    """Test move file."""
    fs = XRootDPyFS(mkurl(tmppath))

    src_exists = "data/testa.txt"
    dst_exists = "data/multiline.txt"
    dst_new = "data/ok.txt"
    dst_folder_exists = "data/bfolder/"
    dst_folder_new = "data/anothernewfolder/"
    content = _get_content(fs, src_exists)

    assert fs.exists(dst_exists)
    assert not fs.exists(dst_new)
    assert fs.exists(dst_folder_exists)
    assert not fs.exists(dst_folder_new)

    fs.copy(src_exists, dst_new)
    assert fs.exists(src_exists) and fs.exists(dst_new)

    fs.copy(src_exists, dst_folder_new)
    assert fs.exists(src_exists) and fs.exists(dst_folder_new)

    fs.copy(src_exists, dst_exists, overwrite=True)
    assert fs.exists(src_exists) and fs.exists(dst_exists)
    assert content == _get_content(fs, dst_exists)

    fs.copy(src_exists, dst_folder_exists, overwrite=True)
    assert fs.exists(src_exists) and fs.exists(dst_folder_exists)
    assert content == _get_content(fs, dst_folder_exists)
Ejemplo n.º 13
0
def test_movedir_good(tmppath):
    """Test move file."""
    fs = XRootDPyFS(mkurl(tmppath))

    src_exists = "data/afolder/"
    dst_exists = "data/multiline.txt"
    dst_new = "data/ok.txt"
    dst_folder_exists = "data/bfolder/"
    dst_folder_new = "data/anothernewfolder/"

    assert fs.isdir(src_exists)
    assert fs.exists(dst_exists)
    assert not fs.exists(dst_new)
    assert fs.exists(dst_folder_exists)
    assert not fs.exists(dst_folder_new)

    fs.movedir(src_exists, dst_new)
    assert not fs.exists(src_exists) and fs.exists(dst_new)

    fs.movedir(dst_new, src_exists)
    fs.movedir(src_exists, dst_folder_new)
    assert not fs.exists(src_exists) and fs.exists(dst_folder_new)

    fs.movedir(dst_folder_new, src_exists)
    fs.movedir(src_exists, dst_exists, overwrite=True)
    assert not fs.exists(src_exists) and fs.exists(dst_exists)
    assert fs.isdir(dst_exists)

    fs.movedir(dst_exists, src_exists)
    fs.movedir(src_exists, dst_folder_exists, overwrite=True)
    assert not fs.exists(src_exists) and fs.exists(dst_folder_exists)
    assert fs.isdir(dst_folder_exists)