本文整理匯總了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")