How to use the pathlib2.WindowsPath function in pathlib2

To help you get started, we’ve selected a few pathlib2 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 mcmtroffaes / pathlib2 / tests / test_pathlib2.py View on Github external
self.assertEqual(p6.expanduser(), p6)
            self.assertRaises(RuntimeError, p7.expanduser)

            env.set('HOME', '/tmp')
            self.assertEqual(p1.expanduser(), P('/tmp/Documents'))
            self.assertEqual(p2.expanduser(), P(userhome) / 'Documents')
            self.assertEqual(p3.expanduser(), P(otherhome) / 'Documents')
            self.assertEqual(p4.expanduser(), p4)
            self.assertEqual(p5.expanduser(), p5)
            self.assertEqual(p6.expanduser(), p6)
            self.assertRaises(RuntimeError, p7.expanduser)


@only_nt
class WindowsPathTest(_BasePathTest, unittest.TestCase):
    cls = pathlib.WindowsPath

    def test_glob(self):
        P = self.cls
        p = P(BASE)
        self.assertEqual(set(p.glob("FILEa")), set([P(BASE, "fileA")]))

    def test_rglob(self):
        P = self.cls
        p = P(BASE, "dirC")
        self.assertEqual(set(p.rglob("FILEd")),
                         set([P(BASE, "dirC/dirD/fileD")]))

    def test_expanduser(self):
        P = self.cls
        with support.EnvironmentVarGuard() as env:
            env.unset('HOME')
github mcmtroffaes / pathlib2 / tests / test_pathlib2.py View on Github external
def test_unsupported_flavour(self):
        if os.name == 'nt':
            self.assertRaises(NotImplementedError, pathlib.PosixPath)
        else:
            self.assertRaises(NotImplementedError, pathlib.WindowsPath)
github CINPLA / exdir / exdir / core / validation.py View on Github external
def thorough(parent_path, name):
    _assert_nonempty(parent_path, name)
    _assert_nonreserved(name)
    try:
        name_str = str(name)
    except UnicodeEncodeError:
        name_str = name.encode('utf8')
    name_lower = name_str.lower()
    _assert_valid_characters(name_lower)

    if isinstance(pathlib.Path(parent_path), pathlib.WindowsPath):
        # use _assert_unique if we're already on Windows, because it is much faster
        # than the test below
        _assert_unique(parent_path, name)
        return

    # os.listdir is much faster here than os.walk or parent_path.iterdir
    for item in os.listdir(str(parent_path)):
        if name_lower == item.lower():
            raise RuntimeError(
                "A directory with name (case independent) '{}' already exists "
                " and cannot be made according to the naming rule 'thorough'.".format(name)
            )