Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_relative(self):
"""Test relative path."""
abspath = os.path.abspath('.')
p = pathlib.Path(abspath)
with change_cwd(os.path.dirname(abspath)):
results = list(p.glob('docs/**/*.md', flags=pathlib.GLOBSTAR))
self.assertTrue(len(results))
self.assertTrue(all([file.suffix == '.md' for file in results]))
def test_instance(self):
"""Test instance."""
p1 = pathlib.Path('wcmatch')
p2 = pypathlib.Path('wcmatch')
self.assertTrue(isinstance(p1, pathlib.Path))
self.assertTrue(isinstance(p1, pypathlib.Path))
self.assertFalse(isinstance(p2, pathlib.Path))
self.assertTrue(isinstance(p2, pypathlib.Path))
def test_match_root_dir_pathlib(self):
"""Test root directory with `globmatch` using `pathlib`."""
from wcmatch import pathlib
self.assertFalse(glob.globmatch(pathlib.Path('markdown'), 'markdown', flags=glob.REALPATH))
self.assertTrue(
glob.globmatch(pathlib.Path('markdown'), 'markdown', flags=glob.REALPATH, root_dir=pathlib.Path('docs/src'))
)
p = cls.globjoin(cls.tempdir, p)
else:
p = cls.tempdir
res = glob.glob(p, **kwargs)
print("RESULTS: ", res)
if res:
cls.assert_equal({type(r) for r in res}, {str})
cls.assert_count_equal(glob.iglob(p, **kwargs), res)
if 'root_dir' in kwargs and kwargs['root_dir'] is not None:
kwargs['root_dir'] = os.fsencode(kwargs['root_dir'])
bres = [os.fsencode(x) for x in res]
cls.assert_count_equal(glob.glob(os.fsencode(p), **kwargs), bres)
cls.assert_count_equal(glob.iglob(os.fsencode(p), **kwargs), bres)
if bres:
cls.assert_equal({type(r) for r in bres}, {bytes})
return res
self.assertEqual([filepath], glob.glob(filepath.replace('\\', '\\\\'), flags=glob.C))
self.assertEqual(
[self.RE_DRIVE.sub(lambda m: m.group(0).upper(), filepath)],
glob.glob(self.RE_DRIVE.sub(lambda m: m.group(0).upper(), filepath).replace('\\', '\\\\'), flags=glob.C)
)
self.assertEqual(
[self.RE_DRIVE.sub(lambda m: m.group(0).lower(), filepath)],
glob.glob(self.RE_DRIVE.sub(lambda m: m.group(0).lower(), filepath).replace('\\', '\\\\'), flags=glob.C)
)
@skip_unless_symlink
class TestSymlinkLoopGlob(unittest.TestCase):
"""Symlink loop test case."""
DEFAULT_FLAGS = glob.BRACE | glob.EXTGLOB | glob.GLOBSTAR | glob.FOLLOW
def globjoin(self, *parts):
"""Joins glob path."""
sep = os.fsencode(self.globsep) if isinstance(parts[0], bytes) else self.globsep
return sep.join(list(parts))
def setUp(self):
"""Setup."""
if os.sep == '/':
self.globsep = os.sep
else:
self.globsep = r'\\'
def test_selflink(self):
def setUp(self):
"""Setup."""
self.tempdir = TESTFN + "_dir"
self.default_flags = glob.G | glob.P
def setup_class(cls):
"""Setup default flag options."""
# The tests we scraped were written with this assumed.
cls.flags = glob.NEGATE | glob.GLOBSTAR | glob.EXTGLOB | glob.BRACE
Options(default_negate='sym3/EF'),
[
('**', 'EF'),
[
] if not can_symlink() else [
],
glob.N | glob.L
],
[
('**', 'EF'),
[
] if not can_symlink() else [
],
glob.N
],
Options(default_negate='**'),
# Disable symlinks
[
('a*', '**'),
[
('EF',), ('ZZZ',), ('',)
] if not can_symlink() else [
('EF',), ('ZZZ',), ('',), ('sym1',), ('sym2',)
],
glob.N | glob.L
],
Options(cwd_temp=True, absolute=True),
['!(.)', ['abc'], glob.M],
[r'!(\.)', ['abc'], glob.M],
[r'!(\x2e)', ['abc'], glob.M | glob.R],
['@(!(.))', ['abc'], glob.M],
['!(@(.))', ['abc'], glob.M],
['+(!(.))', ['abc'], glob.M],
['!(+(.))', ['abc'], glob.M],
['!(?)', ['abc'], glob.M],
['!(*)', [], glob.M],
['!([.])', ['abc'], glob.M],
['!(.)', ['..', '.abc', 'abc'], glob.M | glob.D],
[r'!(\.)', ['..', '.abc', 'abc'], glob.M | glob.D],
[r'!(\x2e)', ['..', '.abc', 'abc'], glob.M | glob.R | glob.D],
['@(!(.))', ['..', '.abc', 'abc'], glob.M | glob.D],
['!(@(.))', ['..', '.abc', 'abc'], glob.M | glob.D],
['+(!(.))', ['..', '.abc', 'abc'], glob.M | glob.D],
['+(!(.))', ['.abc', 'abc'], glob.M | glob.D | glob.Z],
['!(+(.))', ['.abc', 'abc'], glob.M | glob.D],
['!(?)', ['.abc', 'abc'], glob.M | glob.D],
['!(*)', [], glob.M | glob.D],
['!([.])', ['.abc', 'abc'], glob.M | glob.D],
['@(..|.)', ['.', '..']],
['@(..|.)', ['.', '..'], glob.Z],
# More extended pattern dot related tests
['*(.)', ['.', '..']],
[r'*(\.)', ['.', '..']],
['*([.])', []],
['*(?)', ['abc']],
['@(.?)', ['..']],
['@(?.)', []],
['*(.)', ['.', '..'], glob.D],
def setUp(self):
"""Setup."""
self.tempdir = TESTFN + "_dir"
self.mktemp('.hidden', 'a.txt')
self.mktemp('.hidden', 'b.file')
self.mktemp('.hidden_file')
self.mktemp('a.txt')
self.mktemp('b.file')
self.mktemp('c.txt.bak')
self.can_symlink = can_symlink()
if self.can_symlink:
self.mksymlink('.hidden', self.norm('sym1'))
self.mksymlink(os.path.join('.hidden', 'a.txt'), self.norm('sym2'))
self.default_flags = glob.G | glob.P | glob.B