當前位置: 首頁>>代碼示例>>Python>>正文


Python URI.listdir方法代碼示例

本文整理匯總了Python中abl.vpath.base.URI.listdir方法的典型用法代碼示例。如果您正苦於以下問題:Python URI.listdir方法的具體用法?Python URI.listdir怎麽用?Python URI.listdir使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在abl.vpath.base.URI的用法示例。


在下文中一共展示了URI.listdir方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_listdir

# 需要導入模塊: from abl.vpath.base import URI [as 別名]
# 或者: from abl.vpath.base.URI import listdir [as 別名]
 def test_listdir(self):
     base_path = URI('zip://((%s))/' % self.zip_path.uri)
     self.assertEqual(base_path.listdir(), [])
     p1 = URI('zip://((%s))/foo.txt' % self.zip_path.uri)
     with p1.open('wb') as fd:
         fd.write(b'foo')
     self.assertEqual(base_path.listdir(), ['foo.txt'])
     p2 = URI('zip://((%s))/dir/foo.txt' % self.zip_path.uri)
     with p2.open('w') as fd:
         fd.write(b'foo')
     self.assertEqual(set(base_path.listdir()), set(['foo.txt', 'dir']))
開發者ID:AbletonAG,項目名稱:abl.vpath,代碼行數:13,代碼來源:test_zip.py

示例2: test_walk

# 需要導入模塊: from abl.vpath.base import URI [as 別名]
# 或者: from abl.vpath.base.URI import listdir [as 別名]
 def test_walk(self):
     root = URI('zip://((%s))/' % self.zip_path.uri)
     self.assertEqual(len(root.listdir()), 2)
     rlist = []
     for base, dirs, files in root.walk():
         rlist.append((base, dirs, files))
     self.assertEqual(rlist,
                      [(root, ['dir1'], ['bar.txt']),
                       ((root / 'dir1'), [], ['bar.txt', 'foo.txt'])])
開發者ID:AbletonAG,項目名稱:abl.vpath,代碼行數:11,代碼來源:test_zip.py

示例3: MemoryFSTests

# 需要導入模塊: from abl.vpath.base import URI [as 別名]
# 或者: from abl.vpath.base.URI import listdir [as 別名]
class MemoryFSTests(CleanupMemoryBeforeTestMixin, TestCase):

    def setUp(self):
        super(MemoryFSTests, self).setUp()
        self.temp_path = URI(tempfile.mktemp())
        self.temp_path.mkdir()
        self.root = URI("memory:///")


    def tearDown(self):
        if self.temp_path.isdir():
            self.temp_path.remove(recursive=True)
        super(MemoryFSTests, self).tearDown()


    def test_all(self):
        root = self.root
        assert root.isdir()

        subdir = root / "foo"

        subdir.mkdir()

        assert subdir.isdir()
        assert not subdir.isfile()

        out = subdir / "bar"

        with out.open("w") as outf:
            outf.write("foobar")

        assert not out.isdir()
        assert out.isfile()

        with out.open() as inf:
            content = inf.read()
            self.assertEqual(content, "foobar")


        assert subdir == root / "foo"

        time.sleep(.5)
        assert out.info().mtime < time.time()

        connection = subdir.connection
        out = StringIO()
        connection.dump(out)
        print((out.getvalue()))


    def test_write_text_read_binary(self):
        test_file = self.root / 'foo'
        with test_file.open('w') as text_proxy:
            text_proxy.write("spam & eggs")
        with test_file.open('rb') as binary_proxy:
            self.assertEqual(binary_proxy.read(), b"spam & eggs")


    def test_write_binary_read_text(self):
        test_file = self.root / 'foo'
        with test_file.open('wb') as binary_proxy:
            binary_proxy.write(b"spam & eggs")
        with test_file.open('r') as text_proxy:
            self.assertEqual(text_proxy.read(), "spam & eggs")


    def test_info_on_symlinks(self):
        root = self.root
        a_file = root / "a_file"
        a_link = root / "a_link"
        with a_file.open('w') as f:
            f.write("a" * 800)
        a_file.symlink(a_link)

        self.assertEqual(a_file.info().size, 800)
        self.assertEqual(a_link.info().size, 800)
        self.assertNotEqual(a_link.info(followlinks=False).size, 800)

        orig_info = a_file.info()
        new_info = a_file.info()
        new_info.mtime = new_info.mtime + 100
        a_link.info(new_info, followlinks=False)

        self.assertEqual(a_file.info().mtime, orig_info.mtime)
        self.assertEqual(a_link.info().mtime, orig_info.mtime)
        self.assertEqual(a_link.info(followlinks=False).mtime, new_info.mtime)


    def test_listdir_empty_root(self):
        root = self.root
        files = root.listdir()
        assert not files


    def test_listdir_empty_dir(self):
        root = self.root
        foo = root / 'foo'
        foo.mkdir()
        rootfiles = root.listdir()
        assert 'foo' in rootfiles
#.........這裏部分代碼省略.........
開發者ID:AbletonAG,項目名稱:abl.vpath,代碼行數:103,代碼來源:test_memory.py

示例4: TestRemovalOfFilesAndDirs

# 需要導入模塊: from abl.vpath.base import URI [as 別名]
# 或者: from abl.vpath.base.URI import listdir [as 別名]
class TestRemovalOfFilesAndDirs(CleanupMemoryBeforeTestMixin, TestCase):

    def setUp(self):
        super(TestRemovalOfFilesAndDirs, self).setUp()
        self.root_path = URI('memory:///')

    def test_first(self):
        self.assertEqual(self.root_path.listdir(),[])

    def test_removedir(self):
        dir_path = self.root_path / 'foo'
        self.assertTrue(not dir_path.exists())
        dir_path.mkdir()
        self.assertTrue(dir_path.exists())
        self.assertTrue(dir_path.isdir())
        dir_path.remove()
        self.assertTrue(not dir_path.exists())

    def test_remove_not_existing_dir(self):
        dir_path = self.root_path / 'foo'
        self.assertRaises(FileDoesNotExistError, dir_path.remove, ())

    def test_removefile(self):
        file_path = self.root_path / 'foo.txt'
        self.assertTrue(not file_path.exists())
        with file_path.open('w') as fd:
            fd.write('bar')
        self.assertTrue(file_path.isfile())
        file_path.remove()
        self.assertTrue(not file_path.exists())


    def test_removefile_not_existing(self):
        file_path = self.root_path / 'foo.txt'
        self.assertRaises(FileDoesNotExistError, file_path.remove, ())


    def test_remove_recursive(self):
        dir_path = self.root_path / 'foo'
        file_path = dir_path / 'bar.txt'
        dir_path.mkdir()
        with file_path.open('w') as fd:
            fd.write('info')
        self.assertTrue(dir_path.exists())
        self.assertTrue(file_path.exists())
        dir_path.remove(recursive=True)
        self.assertTrue(not dir_path.exists())
        self.assertTrue(not file_path.exists())


    def test_locking(self):
        p = self.root_path / "test.txt"
        try:
            content = "I'm something written into a locked file"
            with p.lock() as inf:
                inf.write(content)
            self.assertEqual(p.open().read(), content)
        finally:
            if p.exists():
                p.remove()

        mfile = p.open("w")

        lock_a = mfile.lock
        mfile.close()

        mfile = p.open("w")
        assert lock_a is mfile.lock

        # artificially lock the file
        mfile.lock.acquire()

        try:
            with p.lock(fail_on_lock=True):
                assert False, "we shouldn't be allowed here!"
        except LockFileObtainException:
            pass
        finally:
            mfile.lock.release()


    def test_manipulation_api(self):
        p = self.root_path / "test.txt"
        p._manipulate(lock=True)
        mfile = p.open("w")
        assert not mfile.lock.acquire(False)
        p._manipulate(unlock=True)
        try:
            assert mfile.lock.acquire(False)
        finally:
            mfile.lock.release()

        with p.open("w") as outf:
            outf.write("foo")

        old_mtime = p.mtime()
        new_mtime = old_mtime + 100
        p._manipulate(mtime=new_mtime)

        self.assertEqual(p.mtime(), new_mtime)
#.........這裏部分代碼省略.........
開發者ID:AbletonAG,項目名稱:abl.vpath,代碼行數:103,代碼來源:test_memory.py

示例5: test_listdir

# 需要導入模塊: from abl.vpath.base import URI [as 別名]
# 或者: from abl.vpath.base.URI import listdir [as 別名]
 def test_listdir(self):
     path = URI(self.existing_dir)
     dirs = path.listdir()
     self.assertTrue('foo.txt' in dirs)
開發者ID:AbletonAG,項目名稱:abl.vpath,代碼行數:6,代碼來源:test_fs.py


注:本文中的abl.vpath.base.URI.listdir方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。