示例#1
0
def test_bool_cast():
    p = Path() / 'setup.py'
    if not p:
        assert False, 'Path should evaluate to True if exists'

    p = Path() / 'not-exists.dummy'
    if p:
        assert False, 'Path should evaluate to False if not exists'
示例#2
0
def test_dsl_recursive():
    p = Path('./pysh')  # make the test faster :)
    q = p**'precedence.py'
    assert sorted(q.iter_posix()) == ['pysh/transforms/precedence.py']

    q = p**'transforms/precede*.py'
    assert sorted(q.iter_posix()) == ['pysh/transforms/precedence.py']

    q = p**re.compile(r'pr[ecd]+nce.py')
    assert sorted(q.iter_posix()) == ['pysh/transforms/precedence.py']

    fn = lambda p: p.is_file() and p.name == 'precedence.py'
    q = p**fn
    assert sorted(q.iter_posix()) == ['pysh/transforms/precedence.py']
示例#3
0
def test_dsl_callable():
    fn = lambda p: p.is_dir() and p.name == 'pysh'
    p = Path('.')
    q = p // fn

    assert type(q) == FilterMatcher
    assert sorted(q.iter_posix()) == ['./pysh']
示例#4
0
def test_dsl_glob():
    p = Path('.')
    q = p // '*.cfg'

    assert p is not q
    assert type(q) == GlobMatcher
    assert list(q.iter_posix()) == ['./setup.cfg']
示例#5
0
def test_dsl_glob_paths():
    p = Path('.')
    q = p // 'setup.py'

    files = sorted(q)
    assert len(files) == 1
    assert type(files[0]) == Path
    assert files[0].as_posix() == 'setup.py'
示例#6
0
def test_dsl_sanity():
    p = Path('.')
    q = p / 'f/o/o'

    assert str(p) == '.'
    assert type(q) == Path
    assert str(q) == 'f/o/o'
    assert len(q.parents) == 3
示例#7
0
def test_dsl_regex():
    p = Path('.')
    q = p // re.compile(r'setup\.(py|cfg)')

    assert type(q) == RegexMatcher
    assert sorted(q.iter_posix()) == ['./setup.cfg', './setup.py']

    q = p // re.compile(r'setup\.p')  # no partial matches
    assert sorted(q.iter_posix()) == []
示例#8
0
文件: pathpow.py 项目: drslump/pysh
    def __rpow__(self, lhs):
        if isinstance(lhs, (str, PurePath)):
            return RecursiveMatcher(Path(lhs), self.rhs)

        return lhs ** self.rhs
示例#9
0
def test_cmd_gt_path():
    expr = foo > Path('out.txt')
    assert type(expr) is Redirect
    assert type(expr.rhs) is Path
示例#10
0
def test_cmd_piperr_path():
    expr = foo ^ Path('errors.log')
    assert type(expr) is Piperr
    assert type(expr.rhs) is Path
示例#11
0
def test_path_pipe_cmd():
    # not implemented yet
    with pytest.raises(TypeError):
        expr = Path('test.txt') | foo
示例#12
0
def test_cmd_pipe_path():
    with pytest.raises(TypeError):
        expr = foo | Path('test.txt')
示例#13
0
def test_str_eq():
    p = Path()

    assert Path('.') == '.'
示例#14
0
def test_dsl_anchors():
    p = Path()

    assert str(p['.']) == '.'
    assert str(p['~'].expanduser()) == os.path.expanduser('~')
    assert str(p['/']) == '/'
示例#15
0
def test_relative():
    p = Path('.')
    assert str(p) == '.'
    assert str(p.resolve()) == os.path.realpath('.')
示例#16
0
def test_dsl_glob_expansion():
    p = Path('.')
    q = p // 'setu?.{cfg,py}'

    assert sorted(q.iter_posix()) == ['./setup.cfg', './setup.py']