Beispiel #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'
Beispiel #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']
Beispiel #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']
Beispiel #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']
Beispiel #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'
Beispiel #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
Beispiel #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()) == []
Beispiel #8
0
    def __rpow__(self, lhs):
        if isinstance(lhs, (str, PurePath)):
            return RecursiveMatcher(Path(lhs), self.rhs)

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

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

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

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