• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python test.assert_raises函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中test.assert_raises函数的典型用法代码示例。如果您正苦于以下问题:Python assert_raises函数的具体用法?Python assert_raises怎么用?Python assert_raises使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了assert_raises函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: test_alt_collection

    def test_alt_collection(self):
        db = self.cx.pymongo_test
        alt = yield motor.MotorGridFS(db, 'alt').open()
        oid = yield alt.put(b("hello world"))
        gridout = yield alt.get(oid)
        self.assertEqual(b("hello world"), (yield gridout.read()))
        self.assertEqual(1, (yield db.alt.files.count()))
        self.assertEqual(1, (yield db.alt.chunks.count()))

        yield alt.delete(oid)
        with assert_raises(NoFile):
            yield alt.get(oid)
        self.assertEqual(0, (yield db.alt.files.count()))
        self.assertEqual(0, (yield db.alt.chunks.count()))

        with assert_raises(NoFile):
            yield alt.get("foo")
        oid = yield alt.put(b("hello world"), _id="foo")
        self.assertEqual("foo", oid)
        gridout = yield alt.get("foo")
        self.assertEqual(b("hello world"), (yield gridout.read()))

        yield alt.put(b(""), filename="mike")
        yield alt.put(b("foo"), filename="test")
        yield alt.put(b(""), filename="hello world")

        self.assertEqual(set(["mike", "test", "hello world"]),
                         set((yield alt.list())))
开发者ID:bdarnell,项目名称:motor,代码行数:28,代码来源:test_motor_gridfs.py


示例2: test_max_time_ms_getmore

    def test_max_time_ms_getmore(self):
        # Cursor handles server timeout during getmore, also.
        yield self.collection.insert({} for _ in range(200))
        try:
            # Send initial query.
            cursor = self.collection.find().max_time_ms(1)
            yield cursor.fetch_next
            cursor.next_object()

            # Test getmore timeout.
            yield self.enable_timeout()
            with assert_raises(ExecutionTimeout):
                while (yield cursor.fetch_next):
                    cursor.next_object()

            # Send another initial query.
            yield self.disable_timeout()
            cursor = self.collection.find().max_time_ms(1)
            yield cursor.fetch_next
            cursor.next_object()

            # Test getmore timeout.
            yield self.enable_timeout()
            with assert_raises(ExecutionTimeout):
                yield cursor.to_list(None)

            # Avoid 'IOLoop is closing' warning.
            yield cursor.close()
        finally:
            # Cleanup.
            yield self.disable_timeout()
            yield self.collection.remove()
开发者ID:jeffreywugz,项目名称:motor,代码行数:32,代码来源:test_motor_cursor.py


示例3: test_def_operations

    def test_def_operations(self):
        """test get/list/has def"""

        template = Template("""

            this is the body

            <%def name="a()">
                this is a
            </%def>

            <%def name="b(x, y)">
                this is b, ${x} ${y}
            </%def>

        """)

        assert template.get_def("a")
        assert template.get_def("b")
        assert_raises(AttributeError,
                      template.get_def,
                      ("c")
                      )

        assert template.has_def("a")
        assert template.has_def("b")
        assert not template.has_def("c")

        defs = template.list_defs()
        assert "a" in defs
        assert "b" in defs
        assert "body" in defs
        assert "c" not in defs
开发者ID:whiteclover,项目名称:Choco,代码行数:33,代码来源:test_def.py


示例4: test_copy_db_auth

    def test_copy_db_auth(self):
        # See SERVER-6427.
        cx = self.get_client()
        if cx.is_mongos:
            raise SkipTest("Can't copy database with auth via mongos.")

        target_db_name = "motor_test_2"

        collection = cx.motor_test.test_collection
        yield collection.remove()
        yield collection.insert({"_id": 1})

        yield cx.admin.add_user("admin", "password")
        yield cx.admin.authenticate("admin", "password")

        try:
            yield cx.motor_test.add_user("mike", "password")

            with assert_raises(pymongo.errors.OperationFailure):
                yield cx.copy_database("motor_test", target_db_name, username="foo", password="bar")

            with assert_raises(pymongo.errors.OperationFailure):
                yield cx.copy_database("motor_test", target_db_name, username="mike", password="bar")

            # Copy a database using name and password.
            yield cx.copy_database("motor_test", target_db_name, username="mike", password="password")

            self.assertEqual({"_id": 1}, (yield cx[target_db_name].test_collection.find_one()))

            yield cx.drop_database(target_db_name)
        finally:
            yield remove_all_users(cx.motor_test)
            yield cx.admin.remove_user("admin")
开发者ID:hackdog,项目名称:motor,代码行数:33,代码来源:motor_client_test_generic.py


示例5: test_strict

    def test_strict(self):
        t = Template("""
            % if x is UNDEFINED:
                undefined
            % else:
                x: ${x}
            % endif
        """, strict_undefined=True)

        assert result_lines(t.render(x=12)) == ['x: 12']

        assert_raises(
            NameError,
            t.render, y=12
        )

        l = TemplateLookup(strict_undefined=True)
        l.put_string("a", "some template")
        l.put_string("b", """
            <%namespace name='a' file='a' import='*'/>
            % if x is UNDEFINED:
                undefined
            % else:
                x: ${x}
            % endif
        """)

        assert result_lines(t.render(x=12)) == ['x: 12']

        assert_raises(
            NameError,
            t.render, y=12
        )
开发者ID:SvenDowideit,项目名称:clearlinux,代码行数:33,代码来源:test_template.py


示例6: test_copy_db_auth

    def test_copy_db_auth(self):
        # SERVER-6427, can't copy database via mongos with auth.
        yield skip_if_mongos(self.cx)

        yield self.collection.insert({'_id': 1})

        try:
            # self.cx is logged in as root.
            yield self.cx.motor_test.add_user('mike', 'password')

            client = self.get_client()
            target_db_name = 'motor_test_2'

            with assert_raises(pymongo.errors.OperationFailure):
                yield client.copy_database(
                    'motor_test', target_db_name,
                    username='foo', password='bar')

            with assert_raises(pymongo.errors.OperationFailure):
                yield client.copy_database(
                    'motor_test', target_db_name,
                    username='mike', password='bar')

            # Copy a database using name and password.
            yield client.copy_database(
                'motor_test', target_db_name,
                username='mike', password='password')

            self.assertEqual(
                {'_id': 1},
                (yield client[target_db_name].test_collection.find_one()))

            yield client.drop_database(target_db_name)
        finally:
            yield remove_all_users(self.cx.motor_test)
开发者ID:Vallher,项目名称:motor,代码行数:35,代码来源:motor_client_test_generic.py


示例7: test_recovering_member_triggers_refresh

    def test_recovering_member_triggers_refresh(self):
        # To test that find_one() and count() trigger immediate refreshes,
        # we'll create a separate client for each
        self.c_find_one, self.c_count = yield [
            motor.MotorReplicaSetClient(
                self.seed, replicaSet=self.name, read_preference=SECONDARY
            ).open() for _ in xrange(2)]

        # We've started the primary and one secondary
        primary = ha_tools.get_primary()
        secondary = ha_tools.get_secondaries()[0]

        # Pre-condition: just make sure they all connected OK
        for c in self.c_find_one, self.c_count:
            self.assertEqual(one(c.secondaries), _partition_node(secondary))

        ha_tools.set_maintenance(secondary, True)

        # Trigger a refresh in various ways
        with assert_raises(AutoReconnect):
            yield self.c_find_one.test.test.find_one()

        with assert_raises(AutoReconnect):
            yield self.c_count.test.test.count()

        # Wait for the immediate refresh to complete - we're not waiting for
        # the periodic refresh, which has been disabled
        yield self.pause(1)

        for c in self.c_find_one, self.c_count:
            self.assertFalse(c.secondaries)
            self.assertEqual(_partition_node(primary), c.primary)
开发者ID:devlato,项目名称:motor,代码行数:32,代码来源:test_motor_ha.py


示例8: test_copy_db

    def test_copy_db(self):
        # 1. Drop old test DBs
        # 2. Copy a test DB N times at once (we need to do it many times at
        #   once to make sure the pool's start_request() is properly isolating
        #   operations from each other)
        # 3. Create a username and password
        # 4. Copy a database using name and password
        ncopies = 10
        test_db_names = ['pymongo_test%s' % i for i in range(ncopies)]

        def check_copydb_results():
            db_names = self.sync_cx.database_names()
            for test_db_name in test_db_names:
                self.assertTrue(test_db_name in db_names)
                result = self.sync_cx[test_db_name].test_collection.find_one()
                self.assertTrue(result, "No results in %s" % test_db_name)
                self.assertEqual(
                    "bar", result.get("foo"),
                    "Wrong result from %s: %s" % (test_db_name, result))

        # 1. Drop old test DBs
        yield self.cx.drop_database('pymongo_test')
        self.drop_databases(test_db_names)

        # 2. Copy a test DB N times at once
        yield self.cx.pymongo_test.test_collection.insert({"foo": "bar"})
        yield [
            self.cx.copy_database("pymongo_test", test_db_name)
            for test_db_name in test_db_names]

        check_copydb_results()
        self.drop_databases(test_db_names)

        # 3. Create a username and password
        yield self.cx.pymongo_test.add_user("mike", "password")

        with assert_raises(pymongo.errors.OperationFailure):
            yield self.cx.copy_database(
                "pymongo_test", "pymongo_test0",
                username="foo", password="bar")

        with assert_raises(pymongo.errors.OperationFailure):
            yield self.cx.copy_database(
                "pymongo_test", "pymongo_test0",
                username="mike", password="bar")

        # 4. Copy a database using name and password
        if not self.cx.is_mongos:
            # See SERVER-6427
            yield [
                self.cx.copy_database(
                    "pymongo_test", test_db_name,
                    username="mike", password="password")
                for test_db_name in test_db_names]

            check_copydb_results()

        self.drop_databases(test_db_names)
开发者ID:ZoeyYoung,项目名称:motor,代码行数:58,代码来源:test_motor_client.py


示例9: test_copy_db_argument_checking

    def test_copy_db_argument_checking(self):
        with assert_raises(TypeError):
            yield self.cx.copy_database(4, "foo")

        with assert_raises(TypeError):
            yield self.cx.copy_database("foo", 4)

        with assert_raises(pymongo.errors.InvalidName):
            yield self.cx.copy_database("foo", "$foo")
开发者ID:ZoeyYoung,项目名称:motor,代码行数:9,代码来源:test_motor_client.py


示例10: test_max_pool_size_validation

    def test_max_pool_size_validation(self):
        with assert_raises(ConfigurationError):
            motor.MotorClient(max_pool_size=-1)

        with assert_raises(ConfigurationError):
            motor.MotorClient(max_pool_size="foo")

        cx = self.motor_client(max_pool_size=100)
        self.assertEqual(cx.max_pool_size, 100)
        cx.close()
开发者ID:rennat,项目名称:motor,代码行数:10,代码来源:test_motor_client.py


示例11: test_copy_db_argument_checking

    def test_copy_db_argument_checking(self):
        cx = self.get_client()
        with assert_raises(TypeError):
            yield cx.copy_database(4, 'foo')

        with assert_raises(TypeError):
            yield cx.copy_database('foo', 4)

        with assert_raises(pymongo.errors.InvalidName):
            yield cx.copy_database('foo', '$foo')
开发者ID:Vallher,项目名称:motor,代码行数:10,代码来源:motor_client_test_generic.py


示例12: test_basic

    def test_basic(self):
        template = Template("""
            <%page args="x, y, z=7"/>

            this is page, ${x}, ${y}, ${z}
""")

        assert flatten_result(template.render(x=5, y=10)) == "this is page, 5, 10, 7"
        assert flatten_result(template.render(x=5, y=10, z=32)) == "this is page, 5, 10, 32"
        assert_raises(TypeError, template.render, y=10)
开发者ID:SvenDowideit,项目名称:clearlinux,代码行数:10,代码来源:test_template.py


示例13: test_raise

 def test_raise(self):
     template = Template("""
         <%
             raise Exception("this is a test")
         %>
 """, format_errors=False)
     assert_raises(
         Exception,
         template.render
         )
开发者ID:whiteclover,项目名称:Choco,代码行数:10,代码来源:test_def.py


示例14: test_max_pool_size_validation

    def test_max_pool_size_validation(self):
        with assert_raises(ConfigurationError):
            motor.MotorClient(host=host, port=port, max_pool_size=-1)

        with assert_raises(ConfigurationError):
            motor.MotorClient(host=host, port=port, max_pool_size="foo")

        cx = motor.MotorClient(host=host, port=port, max_pool_size=100, io_loop=self.io_loop)

        self.assertEqual(cx.max_pool_size, 100)
        cx.close()
开发者ID:jeffreywugz,项目名称:motor,代码行数:11,代码来源:test_motor_client.py


示例15: test_traditional_assignment_plus_undeclared

    def test_traditional_assignment_plus_undeclared(self):
        t = Template(
            """
            t is: ${t}

            <%
                t = 12
            %>
        """
        )
        assert_raises(UnboundLocalError, t.render, t="T")
开发者ID:JasonZengJ,项目名称:puzzle,代码行数:11,代码来源:test_template.py


示例16: test_to_list_argument_checking

    def test_to_list_argument_checking(self):
        # We need more than 10 documents so the cursor stays alive.
        yield self.make_test_data()
        coll = self.collection
        cursor = coll.find()
        yield self.check_optional_callback(cursor.to_list, 10)
        cursor = coll.find()
        with assert_raises(ValueError):
            yield cursor.to_list(-1)

        with assert_raises(TypeError):
            yield cursor.to_list('foo')
开发者ID:jeffreywugz,项目名称:motor,代码行数:12,代码来源:test_motor_cursor.py


示例17: test_max_time_ms_query

    def test_max_time_ms_query(self):
        # Cursor parses server timeout error in response to initial query.
        yield self.enable_timeout()
        cursor = self.collection.find().max_time_ms(1)
        with assert_raises(ExecutionTimeout):
            yield cursor.fetch_next

        cursor = self.collection.find().max_time_ms(1)
        with assert_raises(ExecutionTimeout):
            yield cursor.to_list(10)

        with assert_raises(ExecutionTimeout):
            yield self.collection.find_one(max_time_ms=1)
开发者ID:jeffreywugz,项目名称:motor,代码行数:13,代码来源:test_motor_cursor.py


示例18: test_validate_collection

    def test_validate_collection(self):
        db = self.cx.pymongo_test

        with assert_raises(TypeError):
            yield db.validate_collection(5)
        with assert_raises(TypeError):
            yield db.validate_collection(None)
        with assert_raises(OperationFailure):
            yield db.validate_collection("test.doesnotexist")
        with assert_raises(OperationFailure):
            yield db.validate_collection(db.test.doesnotexist)

        yield db.test.save({"dummy": u"object"})
        self.assertTrue((yield db.validate_collection("test")))
        self.assertTrue((yield db.validate_collection(db.test)))
开发者ID:MeirKriheli,项目名称:motor,代码行数:15,代码来源:test_motor_database.py


示例19: test_unix_socket

    def test_unix_socket(self):
        if not hasattr(socket, "AF_UNIX"):
            raise SkipTest("UNIX-sockets are not supported on this system")

        if (sys.platform == 'darwin' and
                server_started_with_auth(self.sync_cx)):
            raise SkipTest("SERVER-8492")

        mongodb_socket = '/tmp/mongodb-27017.sock'
        if not os.access(mongodb_socket, os.R_OK):
            raise SkipTest("Socket file is not accessible")

        yield motor.MotorClient(
            "mongodb://%s" % mongodb_socket, io_loop=self.io_loop).open()

        client = yield motor.MotorClient(
            "mongodb://%s" % mongodb_socket, io_loop=self.io_loop).open()

        yield client.pymongo_test.test.save({"dummy": "object"})

        # Confirm we can read via the socket
        dbs = yield client.database_names()
        self.assertTrue("pymongo_test" in dbs)
        client.close()

        # Confirm it fails with a missing socket
        client = motor.MotorClient(
            "mongodb:///tmp/non-existent.sock", io_loop=self.io_loop)

        with assert_raises(ConnectionFailure):
            yield client.open()
开发者ID:ZoeyYoung,项目名称:motor,代码行数:31,代码来源:test_motor_client.py


示例20: test_wait_queue_timeout

    def test_wait_queue_timeout(self):
        # Do a find_one that takes 1 second, and set waitQueueTimeoutMS to 500,
        # 5000, and None. Verify timeout iff max_wait_time < 1 sec.
        where_delay = 1
        yield from self.collection.insert({})
        for waitQueueTimeoutMS in (500, 5000, None):
            cx = self.asyncio_client(
                max_pool_size=1, waitQueueTimeoutMS=waitQueueTimeoutMS)

            yield from cx.open()
            pool = cx._get_primary_pool()
            if waitQueueTimeoutMS:
                self.assertEqual(
                    waitQueueTimeoutMS, pool.wait_queue_timeout * 1000)
            else:
                self.assertTrue(pool.wait_queue_timeout is None)

            collection = cx.motor_test.test_collection
            future = collection.find_one({'$where': delay(where_delay)})
            if waitQueueTimeoutMS and waitQueueTimeoutMS < where_delay * 1000:
                with assert_raises(pymongo.errors.ConnectionFailure):
                    yield from collection.find_one()
            else:
                # No error
                yield from collection.find_one()
            yield from future
            cx.close()
开发者ID:snower,项目名称:motor,代码行数:27,代码来源:test_asyncio_pool.py



注:本文中的test.assert_raises函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python test.assert_raises_message函数代码示例发布时间:2022-05-27
下一篇:
Python test.assertEquals函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap