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


Python FileManager._create_directories方法代碼示例

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


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

示例1: test_create_direcotry

# 需要導入模塊: from FileManager import FileManager [as 別名]
# 或者: from FileManager.FileManager import _create_directories [as 別名]
    def test_create_direcotry(self):

        # Successful cases
        root_dir = os.path.join("test")
        test_dirs = []

        # TODO: Test fails if root_dir was not deleted from a previous failing
        #       test run.  I thought I fixed that, but I missed something.
        try:
            # Pick some specific values to verify the right directories get created
            year, month, day = '2001', '09', '11'
            year_dir = os.path.join(root_dir, year)
            expected_dir = os.path.join(root_dir, year, month, day)
            test_dirs.append(expected_dir)

            self.assertFalse(
                os.path.isdir(root_dir),
                "Verify year directory does not exist before creating it")

            f = FileManager(root_dir)
            f._create_directories(root_dir, year, month, day)
            self.assertTrue(
                os.path.isdir(expected_dir),
                "Verify directories created successfully")

            # Make sure the top level directory created has owner, group,
            # and world read/write/execute permission.  I didn't set up
            # proper usernames on different systems, so I want to be able
            # to read, write and delete files from different computers
            # (including from Windows) as different users.
            #
            # Assume Linux since the script is designed to run on
            # Raspberry Pi

            mode = os.stat(year_dir).st_mode & 0o777
            self.assertEqual(
                mode, 0o777,
                "Verity year directory is user, group, world read/write/execute")

            f._create_directories(root_dir, year, month, day)
            self.assertTrue(
                os.path.isdir(expected_dir),
                "Verify create_directories works if the directory already exists")

            # Try making just a day directory (year and month exist)
            day = '12'
            expected_dir = os.path.join(root_dir, year, month, day)
            test_dirs.append(expected_dir)
            self.assertFalse(
                os.path.isdir(expected_dir),
                "Verify day directory does not exist before creating it")

            f._create_directories(root_dir, year, month, day)
            self.assertTrue(
                os.path.isdir(expected_dir),
                "Verify a new day directory was created successfully")


        finally:
            # Clean up - remove directories created just for this test
            for dir in test_dirs:
                os.removedirs(dir)
                self.assertFalse(
                    os.path.isdir(dir),
                    "Verify test directory does not exist after clean up")

            self.assertFalse(
                os.path.isdir(root_dir),
                "Verify root test directory does not exist after clean up")
開發者ID:tomhotch,項目名稱:timelapse,代碼行數:71,代碼來源:test_FileManager.py


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