How to use pathlib2 - 10 common examples

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 schwa / punic / testing / test_example_projects.py View on Github external
def test_local_1():
    with example_work_directory('local_1'):

        assert(Path('Cartfile.resolved').exists() == False)
        output = runner.check_run('punic resolve')
        assert(Path('Cartfile.resolved').open().read() == 'local "A" "."\n')

        # TODO: This should NOT be created by a resolve.
        # assert(Path('Carthage/Checkouts').exists() == False)
        output = runner.check_run('punic fetch')
        assert(Path('Carthage/Checkouts').is_dir() == True)

        # TODO: This should NOT be created by a fetch.
        # assert(Path('Carthage/Build').exists() == False)
        output = runner.check_run('punic build')
        assert(Path('Carthage/Build/Mac/A.framework').exists() == True)
        assert(Path('Carthage/Build/Mac/A.dSYM').exists() == True)
github tribe29 / checkmk / tests / unit / cmk / utils / test_man_pages.py View on Github external
def test_man_page_path_only_shipped():
    assert man_pages.man_page_path("if64") == Path(cmk_path()) / "checkman" / "if64"
    assert man_pages.man_page_path("not_existant") is None
github syslog-ng / syslog-ng / tests / python_functional / src / setup / unit_testcase.py View on Github external
def get_temp_dir(self):
        testcase_name = calculate_testcase_name(self.testcase_context)
        testcase_subdir = "{}_{}".format(self.__get_current_date(), testcase_name)
        temp_dir = Path("/tmp", testcase_subdir)
        temp_dir.mkdir()
        self.__registered_dirs.append(temp_dir)
        return temp_dir
github awdeorio / mailmerge / tests / test_template_message.py View on Github external
"""Attachment with home directory tilde notation file path."""
    template_path = Path(tmpdir/"template.txt")
    template_path.write_text(textwrap.dedent(u"""\
        TO: to@test.com
        FROM: from@test.com
        ATTACHMENT: ~/attachment.txt

        Hello world
    """))

    # Render will throw an error because we didn't create a file in the
    # user's home directory.  We'll just check the filename.
    template_message = TemplateMessage(template_path)
    with pytest.raises(MailmergeError) as err:
        template_message.render({})
    correct_path = Path.home() / "attachment.txt"
    assert str(correct_path) in str(err)
github mcmtroffaes / pathlib2 / tests / test_pathlib2.py View on Github external
self.assertIs(True, P('NUL').is_reserved())
        self.assertIs(True, P('NUL.txt').is_reserved())
        self.assertIs(True, P('com1').is_reserved())
        self.assertIs(True, P('com9.bar').is_reserved())
        self.assertIs(False, P('bar.com9').is_reserved())
        self.assertIs(True, P('lpt1').is_reserved())
        self.assertIs(True, P('lpt9.bar').is_reserved())
        self.assertIs(False, P('bar.lpt9').is_reserved())
        # Only the last component matters
        self.assertIs(False, P('c:/NUL/con/baz').is_reserved())
        # UNC paths are never reserved
        self.assertIs(False, P('//my/share/nul/con/aux').is_reserved())


class PurePathTest(_BasePurePathTest, unittest.TestCase):
    cls = pathlib.PurePath

    def test_concrete_class(self):
        p = self.cls('a')
        self.assertIs(
            type(p),
            pathlib.PureWindowsPath
            if os.name == 'nt' else pathlib.PurePosixPath)

    def test_different_flavours_unequal(self):
        p = pathlib.PurePosixPath('a')
        q = pathlib.PureWindowsPath('a')
        self.assertNotEqual(p, q)

    @unittest.skipIf(sys.version_info < (3, 0),
                     'Most types are orderable in Python 2')
    def test_different_flavours_unordered(self):
github mcmtroffaes / pathlib2 / tests / test_pathlib2.py View on Github external
self.assertEqual(pp, P('/c'))

    def test_div(self):
        # Basically the same as joinpath()
        P = self.cls
        p = P('//a')
        pp = p / 'b'
        self.assertEqual(pp, P('//a/b'))
        pp = P('/a') / '//c'
        self.assertEqual(pp, P('//c'))
        pp = P('//a') / '/c'
        self.assertEqual(pp, P('/c'))


class PureWindowsPathTest(_BasePurePathTest, unittest.TestCase):
    cls = pathlib.PureWindowsPath

    equivalences = _BasePurePathTest.equivalences.copy()
    equivalences.update({
        'c:a': [('c:', 'a'), ('c:', 'a/'), ('/', 'c:', 'a')],
        'c:/a': [
            ('c:/', 'a'), ('c:', '/', 'a'), ('c:', '/a'),
            ('/z', 'c:/', 'a'), ('//x/y', 'c:/', 'a'),
            ],
        '//a/b/': [('//a/b',)],
        '//a/b/c': [
            ('//a/b', 'c'), ('//a/b/', 'c'),
            ],
    })

    def test_str(self):
        p = self.cls('a/b/c')
github mcmtroffaes / pathlib2 / tests / test_pathlib2.py View on Github external
def test_different_flavours_unordered(self):
        p = pathlib.PurePosixPath('a')
        q = pathlib.PureWindowsPath('a')
        with self.assertRaises(TypeError):
            p < q
        with self.assertRaises(TypeError):
            p <= q
        with self.assertRaises(TypeError):
            p > q
        with self.assertRaises(TypeError):
            p >= q
github mcmtroffaes / pathlib2 / tests / test_pathlib2.py View on Github external
def test_concrete_class(self):
        p = self.cls('a')
        self.assertIs(
            type(p),
            pathlib.PureWindowsPath
            if os.name == 'nt' else pathlib.PurePosixPath)
github mcmtroffaes / pathlib2 / tests / test_pathlib2.py View on Github external
def test_different_flavours_unequal(self):
        p = pathlib.PurePosixPath('a')
        q = pathlib.PureWindowsPath('a')
        self.assertNotEqual(p, q)