How to use the wcmatch.pathlib 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_pathlib.py View on Github external
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]))
github facelessuser / wcmatch / tests / test_pathlib.py View on Github external
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))
github facelessuser / wcmatch / tests / test_pathlib.py View on Github external
def test_integrity(self):
        """Test glob integrity, or better put, test the path structure comes out sane."""

        orig = [pathlib.Path(x) for x in glob.iglob('docs/**/*.md', flags=glob.GLOBSTAR)]
        results = list(pathlib.Path('docs').glob('**/*.md', flags=glob.GLOBSTAR))
        self.assertEqual(orig, results)

        orig = [pathlib.Path(x) for x in glob.iglob('**/*.md', flags=glob.GLOBSTAR)]
        results = list(pathlib.Path('').glob('**/*.md', flags=glob.GLOBSTAR))
        self.assertEqual(orig, results)
github facelessuser / wcmatch / tests / test_pathlib.py View on Github external
def setup_class(cls):
        """Setup default flag options."""

        # The tests we scraped were written with this assumed.
        cls.flags = pathlib.NEGATE | pathlib.EXTGLOB | pathlib.BRACE
github facelessuser / wcmatch / tests / test_pathlib.py View on Github external
def test_bad_path(self):
        """Test bad path."""

        with self.assertRaises(NotImplementedError):
            obj = pathlib.PosixPath if os.name == 'nt' else pathlib.WindowsPath
            obj('name')
github facelessuser / wcmatch / tests / test_pathlib.py View on Github external
# `pathlib` doesn't keep trailing slash, so we can't tell it's a directory
        ['some/**/match/', 'some/path/to/match/', False, pathlib.G],
        ['.', '.', True],
        ['.', '', True],

        # `PurePath`
        ['some/*/*/match', 'some/path/to/match', True, pathlib.G, "pure"],
        ['some/**/match', 'some/path/to/match', False, 0, "pure"],
        ['some/**/match', 'some/path/to/match', True, pathlib.G, "pure"],
        ['some/**/match/', 'some/path/to/match/', False, pathlib.G, "pure"],
        ['.', '.', True, 0, "pure"],
        ['.', '', True, 0, "pure"],

        # Force a specific platform with a specific `PurePath`.
        ['//?/C:/**/file.log', r'\\?\C:\Path\path\file.log', True, pathlib.G, "windows"],
        ['/usr/*/bin', '/usr/local/bin', True, pathlib.G, "unix"]
    ]

    @classmethod
    def setup_class(cls):
        """Setup default flag options."""

        # The tests we scraped were written with this assumed.
        cls.flags = pathlib.NEGATE | pathlib.EXTGLOB | pathlib.BRACE

    @classmethod
    def evaluate(cls, case):
        """Evaluate case."""

        pattern = case[0]
        name = case[1]
        goal = case[2]
github facelessuser / wcmatch / tests / test_pathlib.py View on Github external
"""Evaluate case."""

        pattern = case[0]
        name = case[1]
        goal = case[2]
        flags = cls.flags
        path = None
        platform = "auto"
        if len(case) > 3:
            flags ^= case[3]
        if len(case) > 4:
            if case[4] == "windows":
                path = pathlib.PureWindowsPath(name)
                platform = case[4]
            elif case[4] == "unix":
                path = pathlib.PurePosixPath(name)
                platform = case[4]
            elif case[4] == "pure":
                path = pathlib.PurePath(name)
        if path is None:
            path = pathlib.Path(name)

        print('PATH: ', str(path))
        print("PATTERN: ", pattern)
        print("FILE: ", name)
        print("GOAL: ", goal)
        print("FLAGS: ", bin(flags))
        print("Platform: ", platform)

        cls.run(path, pattern, flags, goal)
github facelessuser / wcmatch / tests / test_globmatch.py View on Github external
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'))
        )
github facelessuser / wcmatch / tests / test_globmatch.py View on Github external
def test_match_root_dir_pathlib_bytes(self):
        """Test root directory with `globmatch` using `pathlib`."""

        from wcmatch import pathlib

        self.assertFalse(glob.globmatch(pathlib.Path('markdown'), b'markdown', flags=glob.REALPATH))
        self.assertTrue(
            glob.globmatch(
                pathlib.Path('markdown'),
                b'markdown', flags=glob.REALPATH,
                root_dir=pathlib.Path('docs/src')
            )
github facelessuser / wcmatch / tests / test_glob.py View on Github external
def test_cwd_root_dir_pathlike_bytes(self):
        """Test root level glob when we switch directory via `root_dir` with a path-like object."""

        self.assert_equal(glob.glob(b'EF', root_dir=pathlib.Path(self.tempdir)), [b'EF'])