예제 #1
0
def test_extend_patterns():
    ignore = jujuignore.JujuIgnore(["foo"])
    assert ignore.match("foo", is_dir=False)
    assert not ignore.match("bar", is_dir=False)
    ignore.extend_patterns(["bar"])
    assert ignore.match("foo", is_dir=False)
    assert ignore.match("bar", is_dir=False)
예제 #2
0
def test_jujuignore_multiple_doublestar():
    ignore = jujuignore.JujuIgnore(['foo/**/bar/**/baz'])
    assert ignore.match('/foo/1/2/bar/baz', is_dir=True)
    assert ignore.match('/foo/1/2/bar/1/2/baz', is_dir=True)
    assert ignore.match('/foo/bar/1/2/baz', is_dir=True)
    assert ignore.match('/foo/1/bar/baz', is_dir=True)
    assert ignore.match('/foo/bar/baz', is_dir=True)
예제 #3
0
def test_extend_patterns():
    ignore = jujuignore.JujuIgnore(['foo'])
    assert ignore.match('foo', is_dir=False)
    assert not ignore.match('bar', is_dir=False)
    ignore.extend_patterns(['bar'])
    assert ignore.match('foo', is_dir=False)
    assert ignore.match('bar', is_dir=False)
예제 #4
0
def test_jujuignore_only_root_target_file_or_dir():
    ignore = jujuignore.JujuIgnore(['/target'])
    assert ignore.match('/target', is_dir=True)
    assert not ignore.match('/foo/target', is_dir=True)
    assert not ignore.match('/foo/1target', is_dir=True)
    assert not ignore.match('/foo/target', is_dir=False)
    assert ignore.match('/target', is_dir=False)
예제 #5
0
def assertMatchedAndNonMatched(globs, matched, unmatched, skip_git=False):
    """For a given set of globs, check that it does and doesn't match as expected"""
    ignore = jujuignore.JujuIgnore(globs)
    for m in matched:
        assert ignore.match(m,
                            is_dir=False), '{} should have matched'.format(m)
    for m in unmatched:
        assert not ignore.match(
            m, is_dir=False), '{} should not have matched'.format(m)
    if skip_git:
        return
    with tempfile.TemporaryDirectory() as tmpdir:
        subprocess.run(['git', 'init', tmpdir], check=True)
        with open(str(pathlib.Path(tmpdir) / '.gitignore'), 'wt') as gitignore:
            gitignore.writelines([g + '\n' for g in globs])
        input = ''.join([m.lstrip('/') + '\n' for m in matched + unmatched])
        check = True
        if len(matched) == 0:
            # We don't check git return value because it returns nonzero if no paths match
            check = False
        p = subprocess.run(['git', 'check-ignore', '--stdin'],
                           check=check,
                           input=input,
                           stdout=subprocess.PIPE,
                           cwd=tmpdir,
                           universal_newlines=True)
    matched_out = p.stdout.splitlines()
    assert sorted(matched) == sorted(matched_out),\
        'expected exactly {} to match not {}'.format(matched, matched_out)
예제 #6
0
def test_jujuignore_all_py_files_in_foo():
    ignore = jujuignore.JujuIgnore(['/foo/*.py'])
    assert not ignore.match('/target.py', is_dir=True)
    assert not ignore.match('/target.py', is_dir=False)
    assert ignore.match('/foo/target.py', is_dir=True)
    assert ignore.match('/foo/target.py', is_dir=False)
    assert not ignore.match('/foo/sub/target.py', is_dir=False)
예제 #7
0
def test_jujuignore_subdirectory_match():
    ignore = jujuignore.JujuIgnore(["apps/logs/"])
    assert not ignore.match("/logs", is_dir=True)
    assert not ignore.match("/apps", is_dir=True)
    assert ignore.match("/apps/logs", is_dir=True)
    assert not ignore.match("/apps/logs", is_dir=False)
    assert not ignore.match("/apps/foo/logs", is_dir=True)
예제 #8
0
def test_jujuignore_only_root_target_dir():
    ignore = jujuignore.JujuIgnore(["/target/"])
    assert ignore.match("/target", is_dir=True)
    assert not ignore.match("/foo/target", is_dir=True)
    assert not ignore.match("/foo/1target", is_dir=True)
    assert not ignore.match("/foo/target", is_dir=False)
    assert not ignore.match("/target", is_dir=False)
예제 #9
0
def test_jujuignore_subdirectory_match():
    ignore = jujuignore.JujuIgnore(['apps/logs/'])
    assert not ignore.match('/logs', is_dir=True)
    assert not ignore.match('/apps', is_dir=True)
    assert ignore.match('/apps/logs', is_dir=True)
    assert not ignore.match('/apps/logs', is_dir=False)
    assert not ignore.match('/apps/foo/logs', is_dir=True)
예제 #10
0
def test_jujuignore_simple_match():
    ignore = jujuignore.JujuIgnore([
        r"foo",
    ])
    assert ignore.match("/foo", is_dir=True)
    assert ignore.match("/bar/foo", is_dir=True)
    assert not ignore.match("/bar/bfoo", is_dir=True)
    assert not ignore.match("/bfoo", is_dir=True)
예제 #11
0
def test_jujuignore_bracket():
    ignore = jujuignore.JujuIgnore([
        r"*.py[cod]",
    ])
    assert not ignore.match("foo.py", is_dir=False)
    assert ignore.match("foo.pyc", is_dir=False)
    assert ignore.match("foo.pyo", is_dir=False)
    assert ignore.match("foo.pyd", is_dir=False)
예제 #12
0
def test_jujuignore_trim_unescaped_trailing_space():
    ignore = jujuignore.JujuIgnore([
        r"foo  ",
        r"bar\ \ ",
    ])
    assert ignore.match("/foo", is_dir=True)
    assert not ignore.match("/bar", is_dir=True)
    assert ignore.match("/bar  ", is_dir=True)
예제 #13
0
def test_jujuignore_paths_with_newlines():
    ignore = jujuignore.JujuIgnore([
        r'bar/**/*.py'
    ])
    assert ignore.match('/bar/foo.py', is_dir=False)
    assert ignore.match('/bar/f\noo.py', is_dir=False)
    assert ignore.match('/bar/baz/f\noo.py', is_dir=False)
    assert ignore.match('/bar/b\nz/f\noo.py', is_dir=False)
예제 #14
0
def test_jujuignore_bracket():
    ignore = jujuignore.JujuIgnore([
        r'*.py[cod]',
    ])
    assert not ignore.match('foo.py', is_dir=False)
    assert ignore.match('foo.pyc', is_dir=False)
    assert ignore.match('foo.pyo', is_dir=False)
    assert ignore.match('foo.pyd', is_dir=False)
예제 #15
0
def test_jujuignore_simple_match():
    ignore = jujuignore.JujuIgnore([
        r'foo',
    ])
    assert ignore.match('/foo', is_dir=True)
    assert ignore.match('/bar/foo', is_dir=True)
    assert not ignore.match('/bar/bfoo', is_dir=True)
    assert not ignore.match('/bfoo', is_dir=True)
예제 #16
0
def test_jujuignore_trim_unescaped_trailing_space():
    ignore = jujuignore.JujuIgnore([
        r'foo  ',
        r'bar\ \ ',
    ])
    assert ignore.match('/foo', is_dir=True)
    assert not ignore.match('/bar', is_dir=True)
    assert ignore.match('/bar  ', is_dir=True)
예제 #17
0
def test_jujuignore_escaped_bang():
    ignore = jujuignore.JujuIgnore([
        r'foo',
        r'!/foo',
        r'\!foo',
    ])
    assert not ignore.match('/foo', is_dir=True)
    assert ignore.match('/bar/foo', is_dir=True)
    assert ignore.match('!foo', is_dir=True)
예제 #18
0
def test_jujuignore_star_match():
    ignore = jujuignore.JujuIgnore([
        r'foo*.py',
    ])
    assert ignore.match('/foo.py', is_dir=False)
    assert ignore.match('/foo2.py', is_dir=False)
    assert ignore.match('/foobar.py', is_dir=False)
    assert ignore.match('/bar/foo.py', is_dir=False)
    assert not ignore.match('/foo/2.py', is_dir=False)
예제 #19
0
def test_jujuignore_escaped_bang():
    ignore = jujuignore.JujuIgnore([
        r"foo",
        r"!/foo",
        r"\!foo",
    ])
    assert not ignore.match("/foo", is_dir=True)
    assert ignore.match("/bar/foo", is_dir=True)
    assert ignore.match("!foo", is_dir=True)
예제 #20
0
def test_jujuignore_all_py_files():
    ignore = jujuignore.JujuIgnore(["*.py"])
    assert not ignore.match("/target", is_dir=True)
    assert ignore.match("/target.py", is_dir=True)
    assert ignore.match("/target.py", is_dir=False)
    assert ignore.match("/foo/target.py", is_dir=True)
    assert ignore.match("/foo/target.py", is_dir=False)
    assert not ignore.match("/target.pyT", is_dir=True)
    assert not ignore.match("/target.pyT", is_dir=False)
예제 #21
0
def test_from_file():
    content = io.StringIO(textwrap.dedent("""\
    foo
    /bar
    """))
    ignore = jujuignore.JujuIgnore(content)
    assert ignore.match("foo", is_dir=False)
    assert ignore.match("/foo", is_dir=False)
    assert ignore.match("/bar", is_dir=False)
    assert not ignore.match("/foo/bar", is_dir=False)
예제 #22
0
def test_jujuignore_everything_under_foo_but_readme():
    ignore = jujuignore.JujuIgnore([
        'foo/**',
        '!foo/README.md',
    ])
    assert not ignore.match('/foo', is_dir=True)
    assert ignore.match('/foo/a', is_dir=True)
    assert ignore.match('/foo/a', is_dir=False)
    assert ignore.match('/foo/a/b', is_dir=False)
    assert not ignore.match('/foo/README.md', is_dir=False)
예제 #23
0
def test_jujuignore_escaped_comment():
    ignore = jujuignore.JujuIgnore([
        "\\#comment",
        "target",
    ])
    assert ignore.match("/target", is_dir=True)
    assert ignore.match("/#comment", is_dir=False)
    assert ignore.match("#comment", is_dir=False)
    assert not ignore.match("/foo/comment", is_dir=False)
    assert ignore.match("/foo/#comment", is_dir=False)
예제 #24
0
def test_jujuignore_escaped_comment():
    ignore = jujuignore.JujuIgnore([
        '\\#comment',
        'target',
    ])
    assert ignore.match('/target', is_dir=True)
    assert ignore.match('/#comment', is_dir=False)
    assert ignore.match('#comment', is_dir=False)
    assert not ignore.match('/foo/comment', is_dir=False)
    assert ignore.match('/foo/#comment', is_dir=False)
예제 #25
0
def test_jujuignore_everything_under_foo_but_readme():
    ignore = jujuignore.JujuIgnore([
        "foo/**",
        "!foo/README.md",
    ])
    assert not ignore.match("/foo", is_dir=True)
    assert ignore.match("/foo/a", is_dir=True)
    assert ignore.match("/foo/a", is_dir=False)
    assert ignore.match("/foo/a/b", is_dir=False)
    assert not ignore.match("/foo/README.md", is_dir=False)
예제 #26
0
def test_from_file():
    content = io.StringIO(textwrap.dedent('''\
    foo
    /bar
    '''))
    ignore = jujuignore.JujuIgnore(content)
    assert ignore.match('foo', is_dir=False)
    assert ignore.match('/foo', is_dir=False)
    assert ignore.match('/bar', is_dir=False)
    assert not ignore.match('/foo/bar', is_dir=False)
예제 #27
0
def test_jujuignore_leading_whitespace():
    ignore = jujuignore.JujuIgnore([
        r'foo',
        r' bar',
        r' #comment',
    ])
    assert ignore.match('/foo', is_dir=True)
    assert ignore.match('/bar', is_dir=True)
    assert ignore.match('/bar/foo', is_dir=True)
    assert not ignore.match('#comment', is_dir=True)
    assert not ignore.match('comment', is_dir=True)
예제 #28
0
def test_jujuignore_leading_whitespace():
    ignore = jujuignore.JujuIgnore([
        r"foo",
        r" bar",
        r" #comment",
    ])
    assert ignore.match("/foo", is_dir=True)
    assert ignore.match("/bar", is_dir=True)
    assert ignore.match("/bar/foo", is_dir=True)
    assert not ignore.match("#comment", is_dir=True)
    assert not ignore.match("comment", is_dir=True)
예제 #29
0
def test_jujuignore_negation():
    ignore = jujuignore.JujuIgnore([
        "*.py",
        "!foo.py",
        "!!!bar.py",
    ])
    assert not ignore.match("bar.py", is_dir=False)
    assert not ignore.match("foo.py", is_dir=False)
    assert ignore.match("baz.py", is_dir=False)
    assert not ignore.match("foo/bar.py", is_dir=False)
    assert not ignore.match("foo/foo.py", is_dir=False)
    assert ignore.match("foo/baz.py", is_dir=False)
예제 #30
0
def test_jujuignore_negation():
    ignore = jujuignore.JujuIgnore([
        '*.py',
        '!foo.py',
        '!!!bar.py',
    ])
    assert not ignore.match('bar.py', is_dir=False)
    assert not ignore.match('foo.py', is_dir=False)
    assert ignore.match('baz.py', is_dir=False)
    assert not ignore.match('foo/bar.py', is_dir=False)
    assert not ignore.match('foo/foo.py', is_dir=False)
    assert ignore.match('foo/baz.py', is_dir=False)