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_match_base_absolute_filepath(self):
"""Test `MATCHBASE` with filepath and an absolute path."""
walker = wcmatch.WcMatch(
self.tempdir,
'.hidden/*.txt', None,
self.default_flags | wcmatch.RECURSIVE | wcmatch.HIDDEN | wcmatch.FILEPATHNAME | wcmatch.MATCHBASE
)
self.crawl_files(walker)
self.assertEqual(
sorted(self.files),
self.norm_list(
['.hidden/a.txt']
)
def test_match_insensitive(self):
"""Test case insensitive."""
walker = wcmatch.WcMatch(
self.tempdir,
'A.TXT', None,
self.default_flags | wcmatch.RECURSIVE | wcmatch.FILEPATHNAME | wcmatch.IGNORECASE
)
self.crawl_files(walker)
self.assertEqual(
sorted(self.files),
self.norm_list(
['a.txt']
)
def test_recursive_hidden_folder_exclude(self):
"""Test non-recursive search."""
walker = wcmatch.WcMatch(
self.tempdir,
'*.txt', '.hidden',
self.default_flags | wcmatch.RECURSIVE | wcmatch.HIDDEN
)
self.crawl_files(walker)
self.assertEqual(self.skipped, 3)
self.assertEqual(sorted(self.files), self.norm_list(['a.txt']))
def test_match_sensitive(self):
"""Test case sensitive."""
walker = wcmatch.WcMatch(
self.tempdir,
'a.txt', None,
self.default_flags | wcmatch.RECURSIVE | wcmatch.FILEPATHNAME | wcmatch.CASE
)
self.crawl_files(walker)
self.assertEqual(
sorted(self.files),
self.norm_list(
['a.txt']
)
def test_sort(self):
"""Test sorting."""
files = wcmatch.WcMatch('.', '*').match()
sorted_files = wcmatch.WcMatch('.', '*', flags=wcmatch.SORT).match()
self.assertNotEqual(files, sorted_files)
self.assertEqual(sorted(files), sorted_files)
def test_recursive_bytes(self):
"""Test non-recursive search."""
walker = wcmatch.WcMatch(
os.fsencode(self.tempdir),
b'*.txt', None,
self.default_flags | wcmatch.RECURSIVE
)
self.crawl_files(walker)
self.assertEqual(self.skipped, 3)
self.assertEqual(sorted(self.files), self.norm_list([b'a.txt']))
def test_match_base_filepath(self):
"""Test `MATCHBASE` with filepath."""
walker = wcmatch.WcMatch(
self.tempdir,
'*.txt', None,
self.default_flags | wcmatch.RECURSIVE | wcmatch.HIDDEN | wcmatch.FILEPATHNAME | wcmatch.MATCHBASE
)
self.crawl_files(walker)
self.assertEqual(
sorted(self.files),
self.norm_list(
['a.txt', '.hidden/a.txt']
)
def test_skip_override(self):
"""Test `on_skip` override."""
walker = wcmatch.WcMatch(
self.tempdir,
'*.txt', None,
self.default_flags | wcmatch.RECURSIVE | wcmatch.HIDDEN
)
walker.on_skip = lambda base, name: ''
self.crawl_files(walker)
self.assertEqual(len(self.skip_records), 4)
def test_sort(self):
"""Test sorting."""
files = wcmatch.WcMatch('.', '*').match()
sorted_files = wcmatch.WcMatch('.', '*', flags=wcmatch.SORT).match()
self.assertNotEqual(files, sorted_files)
self.assertEqual(sorted(files), sorted_files)
def test_abort_early(self):
"""Test aborting early."""
walker = wcmatch.WcMatch(
self.tempdir,
'*.txt*', None,
self.default_flags | wcmatch.RECURSIVE | wcmatch.HIDDEN
)
walker.kill()
records = 0
for f in walker.imatch():
records += 1
self.assertTrue(records == 0 or walker.get_skipped() == 0)