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


Python GridFile.metadata方法代碼示例

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


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

示例1: test_properties

# 需要導入模塊: from gridfs.grid_file import GridFile [as 別名]
# 或者: from gridfs.grid_file.GridFile import metadata [as 別名]
    def test_properties(self):
        self.db.fs.files.remove({})
        self.db.fs.chunks.remove({})

        file = GridFile({"filename": "test"}, self.db, "w")
        self.assertEqual(file.mode, "w")
        self.failIf(file.closed)
        file.close()
        self.assert_(file.closed)

        self.assertRaises(IOError, GridFile, {"filename": "mike"}, self.db)
        a = GridFile({"filename": "test"}, self.db)

        self.assertEqual(a.mode, "r")
        self.failIf(a.closed)

        self.assertEqual(a.length, 0)
        self.assertEqual(a.content_type, None)
        self.assertEqual(a.name, "test")
        self.assertEqual(a.chunk_size, 256000)
        self.assert_(isinstance(a.upload_date, datetime.datetime))
        self.assertEqual(a.aliases, None)
        self.assertEqual(a.metadata, None)
        self.assertEqual(a.md5, "d41d8cd98f00b204e9800998ecf8427e")

        a.content_type = "something"
        self.assertEqual(a.content_type, "something")

        def set_length():
            a.length = 10

        self.assertRaises(AttributeError, set_length)

        def set_chunk_size():
            a.chunk_size = 100

        self.assertRaises(AttributeError, set_chunk_size)

        def set_upload_date():
            a.upload_date = datetime.datetime.utcnow()

        self.assertRaises(AttributeError, set_upload_date)

        a.aliases = ["hello", "world"]
        self.assertEqual(a.aliases, ["hello", "world"])

        a.metadata = {"something": "else"}
        self.assertEqual(a.metadata, {"something": "else"})

        def set_name():
            a.name = "hello"

        self.assertRaises(AttributeError, set_name)

        def set_md5():
            a.md5 = "what"

        self.assertRaises(AttributeError, set_md5)

        a.close()
開發者ID:svetlyak40wt,項目名稱:mongo-python-driver,代碼行數:62,代碼來源:test_grid_file.py


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