How to use the wcmatch.glob.globmatch function in wcmatch

To help you get started, we’ve selected a few wcmatch examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github facelessuser / wcmatch / tests / test_globmatch.py View on Github external
# Number of slashes is inconsequential
        # Glob really looks at what is in between. Multiple slashes are the same as one separator.
        # UNC mounts are special cases and it matters there.
        self.assertTrue(
            all(
                [
                    glob.globmatch(
                        x, '**/../*.{md,py}', flags=self.flags
                    ) for x in glob.glob('**/../*.{md,py}', flags=self.flags)
                ]
            )
        )
        self.assertTrue(
            all(
                [
                    glob.globmatch(
                        x, './**/./../*.py', flags=self.flags
                    ) for x in glob.glob('./**/./../*.py', flags=self.flags)
                ]
            )
        )
        self.assertTrue(
            all(
                [
                    glob.globmatch(
                        x, './///**///./../*.py', flags=self.flags
                    ) for x in glob.glob('./**/.//////..////*.py', flags=self.flags)
                ]
            )
        )
        self.assertTrue(
            all(
github facelessuser / wcmatch / tests / test_globmatch.py View on Github external
def test_globmatch_symlink(self):
        """Test `globmatch` with symlinks."""

        self.assertFalse(glob.globmatch(self.tempdir + '/sym1/a.txt', '**/*.txt}', flags=self.default_flags))
        self.assertTrue(glob.globmatch(self.tempdir + '/a.txt', '**/*.txt', flags=self.default_flags))
github facelessuser / wcmatch / tests / test_globmatch.py View on Github external
)
        )
        self.assertTrue(
            all(
                [
                    glob.globmatch(
                        x, '**/docs/**|!**/*.md', flags=self.flags | glob.SPLIT
                    ) for x in glob.glob('**/docs/**|!**/*.md', flags=self.flags | glob.SPLIT)
                ]
            )
        )

        self.assertTrue(
            all(
                [
                    glob.globmatch(
                        x, '!**/*.md', flags=self.flags | glob.SPLIT
                    ) for x in glob.glob('!**/*.md', flags=self.flags | glob.SPLIT)
                ]
            )
        )
        self.assertFalse(
            all(
                [
                    glob.globmatch(
                        x, '**/docs/**|!**/*.md', flags=self.flags | glob.SPLIT
                    ) for x in glob.glob('**/docs/**', flags=self.flags | glob.SPLIT)
                ]
github facelessuser / wcmatch / tests / test_globmatch.py View on Github external
def test_glob_integrity_marked(self):
        """`globmatch` must match what glob globs with marked directories."""

        # Number of slashes is inconsequential
        # Glob really looks at what is in between. Multiple slashes are the same as one separator.
        # UNC mounts are special cases and it matters there.
        self.assertTrue(
            all(
                [
                    glob.globmatch(
                        x, '**/docs/**', flags=self.flags | glob.MARK
                    ) for x in glob.glob('**/docs/**', flags=self.flags | glob.MARK)
                ]
            )
        )
        self.assertTrue(
            all(
                [
                    glob.globmatch(
                        x, '**/docs/**|!**/*.md', flags=self.flags | glob.SPLIT | glob.MARK
                    ) for x in glob.glob('**/docs/**|!**/*.md', flags=self.flags | glob.SPLIT | glob.MARK)
                ]
            )
        )

        self.assertTrue(
github facelessuser / wcmatch / tests / test_globmatch.py View on Github external
def evaluate(cls, case):
        """Evaluate case."""

        pattern = case[0]
        filename = case[1]
        goal = case[2]
        flags = cls.flags
        if len(case) > 3:
            flags ^= case[3]

        print("PATTERN: ", pattern)
        print("FILE: ", filename)
        print("GOAL: ", goal)
        print("FLAGS: ", bin(flags))

        assert glob.globmatch(filename, pattern, flags=flags) == goal, "Expression did not evaluate as %s" % goal
github facelessuser / wcmatch / tests / test_globmatch.py View on Github external
def test_glob_match_real(self):
        """Test real `globmatch` vs regular `globmatch`."""

        # When there is no context from the file system,
        # `globmatch` can't determine folder with no trailing slash.
        self.assertFalse(glob.globmatch('docs/src', '**/src/**', flags=self.flags))
        self.assertTrue(glob.globmatch('docs/src/', '**/src/**', flags=self.flags))
        self.assertTrue(glob.globmatch('docs/src', '**/src/**', flags=self.flags | glob.REALPATH))
        self.assertTrue(glob.globmatch('docs/src/', '**/src/**', flags=self.flags | glob.REALPATH))

        # Missing files will only match in `globmatch` without context from file system.
        self.assertTrue(glob.globmatch('bad/src/', '**/src/**', flags=self.flags))
        self.assertFalse(glob.globmatch('bad/src/', '**/src/**', flags=self.flags | glob.REALPATH))
github facelessuser / wcmatch / tests / test_globmatch.py View on Github external
def test_glob_match_real_bytes(self):
        """Test real `globmatch` vs regular `globmatch` with bytes strings."""

        # When there is no context from the file system,
        # `globmatch` can't determine folder with no trailing slash.
        self.assertFalse(glob.globmatch(b'docs/src', b'**/src/**', flags=self.flags))
        self.assertTrue(glob.globmatch(b'docs/src/', b'**/src/**', flags=self.flags))
        self.assertTrue(glob.globmatch(b'docs/src', b'**/src/**', flags=self.flags | glob.REALPATH))
        self.assertTrue(glob.globmatch(b'docs/src/', b'**/src/**', flags=self.flags | glob.REALPATH))

        # Missing files will only match in `globmatch` without context from file system.
        self.assertTrue(glob.globmatch(b'bad/src/', b'**/src/**', flags=self.flags))
        self.assertFalse(glob.globmatch(b'bad/src/', b'**/src/**', flags=self.flags | glob.REALPATH))
github facelessuser / wcmatch / tests / test_glob.py View on Github external
if raw:
            self.assertEqual(glob.raw_escape(arg, unix=unix, raw_chars=raw_chars), expected)
            self.assertEqual(glob.raw_escape(os.fsencode(arg), unix=unix, raw_chars=raw_chars), os.fsencode(expected))
            file = (util.norm_pattern(arg, False, True) if raw_chars else arg).replace('\\\\', '\\')
            self.assertTrue(
                glob.globmatch(
                    file,
                    glob.raw_escape(arg, unix=unix, raw_chars=raw_chars),
                    flags=flags
                )
            )
        else:
            self.assertEqual(glob.escape(arg, unix=unix), expected)
            self.assertEqual(glob.escape(os.fsencode(arg), unix=unix), os.fsencode(expected))
            self.assertTrue(
                glob.globmatch(
                    arg,
                    glob.escape(arg, unix=unix),
                    flags=flags
                )
github facelessuser / wcmatch / tests / test_glob.py View on Github external
def check_escape(self, arg, expected, raw=False, unix=None, raw_chars=True):
        """Verify escapes."""

        flags = 0
        if unix is False:
            flags = glob.FORCEWIN
        elif unix is True:
            flags = glob.FORCEUNIX

        if raw:
            self.assertEqual(glob.raw_escape(arg, unix=unix, raw_chars=raw_chars), expected)
            self.assertEqual(glob.raw_escape(os.fsencode(arg), unix=unix, raw_chars=raw_chars), os.fsencode(expected))
            file = (util.norm_pattern(arg, False, True) if raw_chars else arg).replace('\\\\', '\\')
            self.assertTrue(
                glob.globmatch(
                    file,
                    glob.raw_escape(arg, unix=unix, raw_chars=raw_chars),
                    flags=flags
                )
            )
        else:
            self.assertEqual(glob.escape(arg, unix=unix), expected)
            self.assertEqual(glob.escape(os.fsencode(arg), unix=unix), os.fsencode(expected))
            self.assertTrue(
                glob.globmatch(
                    arg,
                    glob.escape(arg, unix=unix),
                    flags=flags
                )