Ejemplo n.º 1
0
def test_makedir(tmppath):
    """Test makedir."""
    rooturl = mkurl(tmppath)

    # Dir in parent
    assert not XRootDFS(rooturl).exists("somedir")
    assert XRootDFS(rooturl).makedir("somedir")
    assert XRootDFS(rooturl).exists("somedir")
    assert exists(join(tmppath, "somedir"))

    # if the path is already a directory, and allow_recreate is False
    print("DestinationExistsError")
    assert pytest.raises(DestinationExistsError,
                         XRootDFS(rooturl).makedir, "data")

    # allow_recreate
    assert XRootDFS(rooturl).makedir("data", allow_recreate=True)

    # if a containing directory is missing and recursive is False
    assert pytest.raises(ResourceInvalidError,
                         XRootDFS(rooturl).makedir, "aa/bb/cc")

    # Recursive
    assert not XRootDFS(rooturl).exists("aa/bb/cc")
    assert XRootDFS(rooturl).makedir("aa/bb/cc", recursive=True)
    assert XRootDFS(rooturl).exists("aa/bb/cc")

    # if a path is an existing file
    assert pytest.raises(DestinationExistsError,
                         XRootDFS(rooturl).makedir, "data/testa.txt")
Ejemplo n.º 2
0
def test_listdir(tmppath):
    """Test listdir."""
    rooturl = mkurl(tmppath)

    dirs = XRootDFS(rooturl).listdir()
    assert len(dirs) == 1
    assert 'data' in dirs

    dirs = XRootDFS(rooturl).listdir("data")
    assert len(dirs) == 3

    dirs = XRootDFS(rooturl + "/data").listdir("afolder", full=True)
    assert 'afolder/afile.txt' in dirs

    dirs = XRootDFS(rooturl + "/data").listdir("afolder/../bfolder", full=True)
    assert 'bfolder/bfile.txt' in dirs

    dirs = XRootDFS(rooturl + "/data").listdir(
        "afolder", absolute=True)
    assert tmppath + "/data/afolder/afile.txt" in dirs

    # abosolute/full conflicts - full wins.
    dirs = XRootDFS(rooturl + "/data").listdir(
        "afolder", absolute=True, full=True)
    assert "afolder/afile.txt" in dirs

    dirs = XRootDFS(rooturl).listdir("data", wildcard="*.txt")
    assert 'testa.txt' in dirs
    assert 'afolder' not in dirs
Ejemplo n.º 3
0
def test_listdir(tmppath):
    """Test listdir."""
    rooturl = mkurl(tmppath)

    dirs = XRootDFS(rooturl).listdir()
    assert len(dirs) == 1
    assert 'data' in dirs

    dirs = XRootDFS(rooturl).listdir("data")
    assert len(dirs) == 3

    dirs = XRootDFS(rooturl + "/data").listdir("afolder", full=True)
    assert 'afolder/afile.txt' in dirs

    dirs = XRootDFS(rooturl + "/data").listdir("afolder/../bfolder", full=True)
    assert 'bfolder/bfile.txt' in dirs

    dirs = XRootDFS(rooturl + "/data").listdir("afolder", absolute=True)
    assert tmppath + "/data/afolder/afile.txt" in dirs

    # abosolute/full conflicts - full wins.
    dirs = XRootDFS(rooturl + "/data").listdir("afolder",
                                               absolute=True,
                                               full=True)
    assert "afolder/afile.txt" in dirs

    dirs = XRootDFS(rooturl).listdir("data", wildcard="*.txt")
    assert 'testa.txt' in dirs
    assert 'afolder' not in dirs
Ejemplo n.º 4
0
def test_makedir(tmppath):
    """Test makedir."""
    rooturl = mkurl(tmppath)

    # Dir in parent
    assert not XRootDFS(rooturl).exists("somedir")
    assert XRootDFS(rooturl).makedir("somedir")
    assert XRootDFS(rooturl).exists("somedir")
    assert exists(join(tmppath, "somedir"))

    # if the path is already a directory, and allow_recreate is False
    print("DestinationExistsError")
    assert pytest.raises(DestinationExistsError, XRootDFS(rooturl).makedir,
                         "data")

    # allow_recreate
    assert XRootDFS(rooturl).makedir("data", allow_recreate=True)

    # if a containing directory is missing and recursive is False
    assert pytest.raises(ResourceInvalidError,
                         XRootDFS(rooturl).makedir, "aa/bb/cc")

    # Recursive
    assert not XRootDFS(rooturl).exists("aa/bb/cc")
    assert XRootDFS(rooturl).makedir("aa/bb/cc", recursive=True)
    assert XRootDFS(rooturl).exists("aa/bb/cc")

    # if a path is an existing file
    assert pytest.raises(DestinationExistsError, XRootDFS(rooturl).makedir,
                         "data/testa.txt")
Ejemplo n.º 5
0
def test_remove(tmppath):
    """Test remove."""
    rooturl = mkurl(tmppath)

    assert XRootDFS(rooturl).exists("data/testa.txt")
    XRootDFS(rooturl).remove("data/testa.txt")
    assert not XRootDFS(rooturl).exists("data/testa.txt")

    # Does not exists
    assert pytest.raises(ResourceInvalidError,
                         XRootDFS(rooturl).remove, "a/testa.txt")

    # Directory not empty
    assert pytest.raises(DirectoryNotEmptyError,
                         XRootDFS(rooturl).remove, "data")

    # Remove emptydir
    assert XRootDFS(rooturl).makedir("emptydir")
    assert XRootDFS(rooturl).remove("emptydir")
Ejemplo n.º 6
0
def test_remove(tmppath):
    """Test remove."""
    rooturl = mkurl(tmppath)

    assert XRootDFS(rooturl).exists("data/testa.txt")
    XRootDFS(rooturl).remove("data/testa.txt")
    assert not XRootDFS(rooturl).exists("data/testa.txt")

    # Does not exists
    assert pytest.raises(ResourceInvalidError, XRootDFS(rooturl).remove,
                         "a/testa.txt")

    # Directory not empty
    assert pytest.raises(DirectoryNotEmptyError, XRootDFS(rooturl).remove,
                         "data")

    # Remove emptydir
    assert XRootDFS(rooturl).makedir("emptydir")
    assert XRootDFS(rooturl).remove("emptydir")
Ejemplo n.º 7
0
def test_opendir(tmppath):
    """Test opendir."""
    rooturl = mkurl(tmppath)
    fs = opener.opendir(rooturl + "/data")
    assert fs.listdir()
Ejemplo n.º 8
0
def test_parse(tmppath):
    """Test parse."""
    rooturl = mkurl(tmppath)
    fs, path = opener.parse(rooturl + "/data")
    assert fs
    assert path == "data"
Ejemplo n.º 9
0
def test_exists(tmppath):
    """Test exists."""
    rooturl = mkurl(tmppath)
    assert XRootDFS(rooturl).exists("data/testa.txt")
    assert XRootDFS(rooturl).exists("data")
    assert not XRootDFS(rooturl).exists("nofile")
Ejemplo n.º 10
0
def test_isdir(tmppath):
    """Test isdir."""
    rooturl = mkurl(tmppath)
    assert not XRootDFS(rooturl).isdir("data/testa.txt")
    assert XRootDFS(rooturl).isdir("data")
    pytest.raises(InvalidPathError, XRootDFS(rooturl).isdir, "nofile")
Ejemplo n.º 11
0
def test_exists(tmppath):
    """Test exists."""
    rooturl = mkurl(tmppath)
    assert XRootDFS(rooturl).exists("data/testa.txt")
    assert XRootDFS(rooturl).exists("data")
    assert not XRootDFS(rooturl).exists("nofile")
Ejemplo n.º 12
0
def test_isdir(tmppath):
    """Test isdir."""
    rooturl = mkurl(tmppath)
    assert not XRootDFS(rooturl).isdir("data/testa.txt")
    assert XRootDFS(rooturl).isdir("data")
    pytest.raises(InvalidPathError, XRootDFS(rooturl).isdir, "nofile")