Exemplo n.º 1
0
def test_open():
    with Story(['io.open', 'os.path.isdir']) as story:
        os.path.isdir(pth.Path('foo')) == False
        io.open(pth.Path('foo'), 'rb') == None

    with story.replay(strict=True):
        pth('foo')('rb')
Exemplo n.º 2
0
def test_abspath_zip():
    with pth.tmp() as tmp:
        pth.Path('tests/files/test.zip').copy(tmp)
        with tmp.cd:
            assert pth("test.zip").abs == tmp / "test.zip"
            assert pth("test.zip").abspath == tmp / "test.zip"
            assert (pth("test.zip") / "a.txt").abs == tmp / "test.zip" / "a.txt"
            assert (pth("test.zip") / "a.txt").abspath == tmp / "test.zip" / "a.txt"
Exemplo n.º 3
0
def test_lchmod():
    with Story(['os.lchmod', 'os.chmod']) as story:
        if PY33:
            os.chmod(pth.Path('foobar'), 0o666, follow_symlinks=False) == None
        else:
            os.lchmod(pth.Path('foobar'), 0o666) == None

    with story.replay(strict=True):
        pth('foobar').lchmod(0o666)
Exemplo n.º 4
0
def test_link():
    with Story(['os.link']) as story:
        if PY33:
            os.link(pth.Path('foo'), 'bar', follow_symlinks=True) == None
        else:
            os.link(pth.Path('foo'), 'bar') == None

    with story.replay(strict=True):
        pth('foo').link('bar')
Exemplo n.º 5
0
def test_parents_zip():
    z = pth('tests', 'files', 'test.zip').joinpath('b', 'c', 'd')
    assert z.parents == [
        pth('tests', 'files', 'test.zip', 'b', 'c'),
        pth('tests', 'files', 'test.zip', 'b'),
        pth('tests', 'files', 'test.zip'),
        pth('tests', 'files'),
        'tests',
    ]
Exemplo n.º 6
0
def test_exists_zip():
    with pth.tmp() as tmp:
        zp = pth.Path('tests/files/test.zip').copy(tmp)
        with tmp.cd:
            assert (pth("test.zip") / "a.txt").exists
            assert not (pth("test.zip") / "crappo").exists

            assert (pth(zp) / "a.txt").exists
            assert not (pth(zp) / "crappo").exists
Exemplo n.º 7
0
def test_lchown():
    with Story(['os.lchown', 'os.chown']) as story:
        if PY33:
            os.chown(pth.Path('foobar'), 123, 123, follow_symlinks=False) == None
        else:
            os.lchown(pth.Path('foobar'), 123, 123) == None

    with story.replay(strict=True):
        pth('foobar').lchown(123, 123)
Exemplo n.º 8
0
def test_time_zip():
    assert isinstance(pth('tests/files/test.zip').atime, float)
    assert isinstance(pth('tests/files/test.zip').ctime, float)
    assert isinstance(pth('tests/files/test.zip').mtime, float)

    a = pth('tests/files/test.zip') / 'a.txt'

    assert raises(NotImplementedError, lambda: a.atime)
    assert isinstance(a.ctime, float)
    assert raises(NotImplementedError, lambda: a.mtime)
Exemplo n.º 9
0
def test_cd():
    assert repr(pth('/bogus').cd) == "pth.WorkingDir('/bogus')"

    with Story(['zipfile.is_zipfile', 'os.chdir', 'os.getcwd', 'os.path.exists', 'os.stat']) as story:
        zipfile.is_zipfile('/bogus') == False  # returns
        os.stat(pth.WorkingDir('/bogus')) == os.stat_result((
            17407, 2621441, 2049, 43, 0, 0, 3805184, 1406286835, 1408573505, 1408573505))  # returns
        os.getcwd() == '/current'  # returns
        os.chdir(pth.WorkingDir('/bogus')) == None  # returns

    with story.replay(strict=False):
        pth('/bogus').cd()
Exemplo n.º 10
0
def test_open_missing():
    with Story(['io.open', 'os.path.isdir']) as story:
        os.path.isdir(pth.Path('foo')) == False
        io.open(pth.Path('foo'), 'rb') ** IOError(errno.ENOENT, "Whatev")

    with story.replay(strict=True):
        raises(pth.PathMustBeFile, lambda: pth('foo')('rb'))
Exemplo n.º 11
0
def test_cd_context_manager_call():
    with Story(['os.stat', 'os.chdir', 'os.getcwd']) as story:
        os.stat(pth.WorkingDir('other')) == Namespace(st_mode=16893)
        os.getcwd() == '/foobar'  # returns
        os.chdir(pth.WorkingDir('other')) == None  # returns
        os.chdir(pth.Path('/foobar')) == None  # returns

    with story.replay(strict=True):
        with pth('other').cd() as wd:
            assert wd == 'other'
            assert wd.previous == '/foobar'
Exemplo n.º 12
0
def test_cd_call():
    with Story(['os.stat', 'os.chdir', 'os.getcwd']) as story:
        os.stat(pth.WorkingDir('other')) == Namespace(st_mode=16893)
        os.getcwd() == '/foobar'  # returns
        os.chdir(pth.WorkingDir('other')) == None  # returns


    with story.replay(strict=True):
        cd = pth('other').cd
        assert cd == 'other'
        assert cd.previous is None
        cd()
Exemplo n.º 13
0
def test_dirname():
    assert pth("/my/abs/path").dir == "/my/abs"
    assert pth("/my/abs/path").dirname == "/my/abs"
    assert pth("path").dir == ""
    assert pth("path").dirname == ""
    assert pth("rel/path").dir == "rel"
    assert pth("rel/path").dirname == "rel"
Exemplo n.º 14
0
def test_basename():
    assert pth("/my/abs/path").name == "path"
    assert pth("/my/abs/path").basename == "path"
    assert pth("path").name == "path"
    assert pth("path").basename == "path"
    assert pth("rel/path").name == "path"
    assert pth("rel/path").basename == "path"
Exemplo n.º 15
0
def test_list():
    assert sorted(list(pth('tests', 'files').list)) == [
        pth('tests', 'files', 'a'),
        pth('tests', 'files', 'b.txt'),
        pth('tests', 'files', 'test.zip'),
        pth('tests', 'files', 'trîcky-năme'),
    ]
    raises(pth.PathMustBeDirectory, next, pth('bogus-doesnt-exist').list)
Exemplo n.º 16
0
def test_normpath():
    p = pth('.', 'tEsts', '..', 'tests')
    assert p.normpath == os.path.normpath(p)
Exemplo n.º 17
0
def test_join_zippath_abs():
    assert pth('tests/files/test.zip') / '/etc' == '/etc'
Exemplo n.º 18
0
def test_relpath_zip():
    r = pth('tests/files')
    p = pth('tests/files/test.zip')
    q = p / 'a'
    assert q.rel(p) == q.relpath(p) == 'a'
    assert p.rel(r) == p.rel(r) == 'test.zip'
Exemplo n.º 19
0
def test_normcase():
    p = pth('.', 'tEsts', '..', 'tests')
    assert p.normcase == os.path.normcase(p)
Exemplo n.º 20
0
def test_realpath():
    p = pth('tests')
    assert p.real == p.realpath == os.path.realpath(p)
Exemplo n.º 21
0
def test_relpath():
    p = pth('tests')
    q = p / 'a' / 'b'
    assert q.rel(p) == q.relpath(p) == pth('a', 'b')
Exemplo n.º 22
0
def test_readlink():
    with Story(['os.readlink']) as story:
        os.readlink(pth.Path('foo')) == 'bar'

    with story.replay(strict=True):
        assert pth('foo').readlink == 'bar'
Exemplo n.º 23
0
def test_samefile():
    assert pth('.').same(pth().abs)
    assert pth('.').samefile(pth().abs)
Exemplo n.º 24
0
def test_access():
    with Story(['os.access']) as story:
        os.access(pth.Path('foo'), os.R_OK) == True

    with story.replay(strict=True):
        assert pth('foo').access(os.R_OK)
Exemplo n.º 25
0
def test_abspath():
    with pth.tmp().cd as tmp:
        assert pth("path").abs == tmp / "path"
        assert pth("path").abspath == tmp / "path"
Exemplo n.º 26
0
def test_chflags_kwargs():
    with Story(['os.lchflags']) as story:
        os.lchflags(pth.Path('foo'), stat.UF_NODUMP) == None

    with story.replay(strict=True):
        pth('foo').chflags(stat.UF_NODUMP, follow_symlinks=True)
Exemplo n.º 27
0
def test_isexecutable_kwargs():
    with Story(['os.access']) as story:
        os.access(pth.Path('foo'), os.R_OK | os.X_OK, follow_symlinks=True) == True

    with story.replay(strict=True):
        assert pth('foo').isexecutable(follow_symlinks=True)
Exemplo n.º 28
0
def test_lexists():
    assert pth("/").lexists
    assert not pth("bogus/doesn't/exist").lexists
Exemplo n.º 29
0
def test_isexecutable():
    with Story(['os.access']) as story:
        os.access(pth.Path('foo'), os.R_OK | os.X_OK) == True

    with story.replay(strict=True):
        assert pth('foo').isexecutable
Exemplo n.º 30
0
def test_lchflags():
    with Story(['os.chflags']) as story:
        os.lchflags(pth.Path('foo'), stat.UF_NODUMP) == None

    with story.replay(strict=True):
        pth('foo').lchflags(stat.UF_NODUMP)