コード例 #1
0
    async def test_create_instance_with_custom_event_loop(self):
        custom_event_loop = get_event_loop_policy().new_event_loop()
        dbm = db.MongoDBManager(DATABASE_SETTING, loop=custom_event_loop)
        await dbm.init_connections()

        assert id(dbm._loop) == id(custom_event_loop)
        assert dbm.is_init is True
        for connection in dbm.connections.values():
            assert connection.io_loop == custom_event_loop
コード例 #2
0
 async def test_is_singleton(self, event_loop):
     # First instance
     dbm = await db.MongoDBManager(DATABASE_SETTING, event_loop).init_connections()
     assert dbm._instance == dbm
     # Second instance
     dbm_clone = db.MongoDBManager(DATABASE_SETTING, event_loop)
     assert dbm_clone == dbm
     assert dbm_clone._instance == dbm
     # Third instance after one more import
     re_imported_db = importlib.import_module('pydantic_odm.db', 'pydantic_odm')
     after_import = re_imported_db.MongoDBManager(  # noqa
         DATABASE_SETTING, event_loop
     )
     assert after_import._instance == dbm
     assert after_import == dbm
コード例 #3
0
ファイル: db.py プロジェクト: ballon3/pydantic-odm
 async def test_create_instance(self):
     raise_msg = 'This is singleton object'
     with pytest.raises(TypeError, match=raise_msg):
         db.MongoDBManager()