Пример #1
0
def test_listing():
    dir = path.tempdir()
    a = dir / 'a'
    b = dir / 'b'
    c = dir / 'c.txt'
    d = dir / 'd.asc'
    dev = path('/dev')
    try:
        a.mkdir()
        b.mkdir()
        c.write_text("foo\n")
        c.symlink(d)
        assert dir.listdir(names_only=True) == \
            ['a', 'b', 'c.txt', 'd.asc']
        assert dir.listdir('*.txt', names_only=True) == \
            ['c.txt']
        assert dir.listdir() == [a, b, c, d]
        assert dir.listdir(symlinks=False) == [a, b, c]
        assert dir.dirs() == [a, b]
        assert dir.dirs(symlinks=False) == [a, b]
        assert dir.files() == [c, d]
        assert dir.files(symlinks=False) == [c]
        assert dir.symlinks() == [d]
        assert dir.symlinks('*.txt') == []
        assert path('/dev/null') not in dev.files()
    finally:
        dir.delete_dammit()
Пример #2
0
def test_constructors():
    assert str(path(P1)) == P1
    assert str(path(P2)) == P2 
    assert str(path(P3)) == P3 
    assert str(path('')) == ''
    assert str(path())   == '' 
    assert str(path.cwd()) == os.getcwd()
Пример #3
0
def test_constructors():
    assert str(path(P1)) == P1
    assert str(path(P2)) == P2
    assert str(path(P3)) == P3
    assert str(path('')) == ''
    assert str(path()) == ''
    assert str(path.cwd()) == os.getcwd()
Пример #4
0
def test_listing():
    dir = path.tempdir()
    a = dir / 'a'
    b = dir / 'b'
    c = dir / 'c.txt'
    d = dir / 'd.asc'
    dev = path('/dev')
    try:
        a.mkdir()
        b.mkdir()
        c.write_text("foo\n")
        c.symlink(d)
        assert dir.listdir(names_only=True) == \
            ['a', 'b', 'c.txt', 'd.asc']
        assert dir.listdir('*.txt', names_only=True) == \
            ['c.txt']
        assert dir.listdir() == [a, b, c, d]
        assert dir.listdir(symlinks=False) == [a, b, c]
        assert dir.dirs() == [a, b]
        assert dir.dirs(symlinks=False) == [a, b]
        assert dir.files() == [c, d]
        assert dir.files(symlinks=False) == [c]
        assert dir.symlinks() == [d]
        assert dir.symlinks('*.txt') == []
        assert path('/dev/null') not in dev.files()
    finally:
        dir.delete_dammit()
Пример #5
0
def test_derivation():
    p = path(P3)
    ap = '/' + p
    assert p.splitpath() == [path(''), 'aaa', 'bbb', 'ccc.txt']
    assert ap.splitpath() == [path('/'), 'aaa', 'bbb', 'ccc.txt']
    assert p.splitext() == (path('aaa/bbb/ccc'), '.txt')
    assert p.stripext() == path('aaa/bbb/ccc')
    assert path('aaa').joinpath('bbb', 'ccc.txt') == p
    assert p.ancestor(2) == path('aaa')
    assert p.ancestor(3) == path('')
    assert p.joinancestor(2, 'foo') == path('aaa/foo')
    assert p.joinancestor(3, 'foo') == path('foo')
Пример #6
0
def test_derivation():
    p = path(P3)
    ap = '/' + p
    assert p.splitpath() == [
        path(''),  'aaa', 'bbb', 'ccc.txt']
    assert ap.splitpath() == [
        path('/'), 'aaa', 'bbb', 'ccc.txt']
    assert p.splitext() == (path('aaa/bbb/ccc'), '.txt')
    assert p.stripext() == path('aaa/bbb/ccc')
    assert path('aaa').joinpath('bbb', 'ccc.txt') == p
    assert p.ancestor(2) == path('aaa')
    assert p.ancestor(3) == path('')
    assert p.joinancestor(2, 'foo') == path('aaa/foo')
    assert p.joinancestor(3, 'foo') == path('foo')
Пример #7
0
def test_repr():
    p = path(P1)
    assert repr(p) == "path(%r)" % P1
    path.repr_as_str = True
    assert repr(p) == "'%s'" % P1
    path.repr_as_str = False
    assert repr(p) == "path(%r)" % P1
Пример #8
0
def test_repr():
    p = path(P1)
    assert repr(p) == "path(%r)" % P1
    path.repr_as_str = True
    assert repr(p) == "'%s'" % P1
    path.repr_as_str = False
    assert repr(p) == "path(%r)" % P1
Пример #9
0
def test_normalization():
    cwd = os.getcwd()
    p = path(P3)
    ap = '/' + p
    assert p.abspath() == os.path.join(cwd, P3)
    assert ap.abspath() == '/' + P3
    assert not p.isabs()
    assert ap.isabs()
    assert p.abspath().relpath() == P3
Пример #10
0
def test_normalization():
    cwd = os.getcwd()
    p = path(P3)
    ap = '/' + p
    assert p.abspath() == os.path.join(cwd, P3)
    assert ap.abspath() == '/' + P3
    assert not p.isabs()
    assert ap.isabs()
    assert p.abspath().relpath() == P3
Пример #11
0
def test_chdir():
    orig_dirs = path.pushed_dirs[:]
    origin = path(os.getcwd())
    tmp = path(tempfile.mkdtemp())
    try:
        # Chdir to tmp.
        tmp.chdir()
        assert os.getcwd() == tmp
        # Return to origin.
        origin.chdir()
        assert os.getcwd() == origin
        # Push to tmp.
        tmp.chdir(True)
        assert os.getcwd() == tmp
        assert path.pushed_dirs == orig_dirs + [origin]
        # Pop back to origin.
        path.popdir()
        assert os.getcwd() == origin
        assert path.pushed_dirs == orig_dirs
    finally:
        os.rmdir(tmp)
Пример #12
0
def test_chdir():
    orig_dirs = path.pushed_dirs[:]
    origin = path(os.getcwd())
    tmp = path(tempfile.mkdtemp())
    try:
        # Chdir to tmp.
        tmp.chdir()
        assert os.getcwd() == tmp
        # Return to origin.
        origin.chdir()
        assert os.getcwd() == origin
        # Push to tmp.
        tmp.chdir(True)
        assert os.getcwd() == tmp
        assert path.pushed_dirs == orig_dirs + [origin]
        # Pop back to origin.
        path.popdir()
        assert os.getcwd() == origin
        assert path.pushed_dirs == orig_dirs
    finally:
        os.rmdir(tmp)
Пример #13
0
def test_relpathto():
    p = path('/home/joe/Mail')
    ancestor = path('/home/joe')
    bad_ancestor = path('BOGUS')
    assert p.relpathfrom(ancestor) == path('Mail')
    py.test.raises(ValueError, p.relpathfrom, bad_ancestor)
Пример #14
0
def test_operators():
    a = "aaa"
    b = "bbb"
    assert path(a) + path(b) == "aaabbb"
    assert path(a) / path(b) == os.path.join(a, b)
Пример #15
0
def test_attributes():
    p = path(P3)
    assert p.parent == path('aaa/bbb')
    assert p.name == 'ccc.txt'
    assert p.base == 'ccc'
    assert p.ext == '.txt'
Пример #16
0
def test_attributes():
    p = path(P3)
    assert p.parent == path('aaa/bbb')
    assert p.name == 'ccc.txt'
    assert p.base == 'ccc'
    assert p.ext == '.txt'
Пример #17
0
def test_relpathto():
    p = path('/home/joe/Mail')
    ancestor = path('/home/joe')
    bad_ancestor = path('BOGUS')
    assert p.relpathfrom(ancestor) == path('Mail')
    py.test.raises(ValueError, p.relpathfrom, bad_ancestor)
Пример #18
0
def test_operators():
    a = "aaa"
    b = "bbb"
    assert path(a) + path(b) == "aaabbb"
    assert path(a) / path(b) == os.path.join(a, b)