当前位置: 首页>>代码示例>>Python>>正文


Python matchers.raises函数代码示例

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


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

示例1: test_base_class

    def test_base_class(self):
        headers = {
            'X-Error-Title': 'Storage service down',
            'X-Error-Description': ('The configured storage service is not '
                                    'responding to requests. Please contact '
                                    'your service provider'),
            'X-Error-Status': falcon.HTTP_503
        }

        expected_body = [
            b'{\n'
            b'    "title": "Storage service down",\n'
            b'    "description": "The configured storage service is not '
            b'responding to requests. Please contact your service provider",\n'
            b'    "code": 10042\n'
            b'}'
        ]

        # Try it with Accept: */*
        headers['Accept'] = '*/*'
        body = self.simulate_request('/fail', headers=headers)
        self.assertEqual(self.srmock.status, headers['X-Error-Status'])
        self.assertThat(lambda: json.loads(body[0]), Not(raises(ValueError)))
        self.assertEqual(expected_body, body)

        # Now try it with application/json
        headers['Accept'] = 'application/json'
        body = self.simulate_request('/fail', headers=headers)
        self.assertEqual(self.srmock.status, headers['X-Error-Status'])
        self.assertThat(lambda: json.loads(body[0]), Not(raises(ValueError)))
        self.assertEqual(body, expected_body)
开发者ID:brandhill,项目名称:falcon,代码行数:31,代码来源:test_httperror.py

示例2: test_base_class

    def test_base_class(self):
        headers = {
            'X-Error-Title': 'Storage service down',
            'X-Error-Description': ('The configured storage service is not '
                                    'responding to requests. Please contact '
                                    'your service provider.'),
            'X-Error-Status': falcon.HTTP_503
        }

        expected_body = {
            'title': 'Storage service down',
            'description': ('The configured storage service is not '
                            'responding to requests. Please contact '
                            'your service provider.'),
            'code': 10042,
        }

        # Try it with Accept: */*
        headers['Accept'] = '*/*'
        body = self.simulate_request('/fail', headers=headers, decode='utf-8')

        self.assertEqual(self.srmock.status, headers['X-Error-Status'])
        self.assertThat(lambda: json.loads(body), Not(raises(ValueError)))
        self.assertEqual(expected_body, json.loads(body))

        # Now try it with application/json
        headers['Accept'] = 'application/json'
        body = self.simulate_request('/fail', headers=headers, decode='utf-8')

        self.assertEqual(self.srmock.status, headers['X-Error-Status'])
        self.assertThat(lambda: json.loads(body), Not(raises(ValueError)))
        self.assertEqual(json.loads(body), expected_body)
开发者ID:JinsongBian,项目名称:falcon,代码行数:32,代码来源:test_httperror.py

示例3: test_find_invalid_usage

 def test_find_invalid_usage(self):
     """
     Passing fewer or more than one query raises `ValueError`.
     """
     enum = Enum('doc', [])
     self.assertThat(enum.find, raises(ValueError))
     self.assertThat(
         lambda: enum.find(foo=u'a', bar=u'b'),
         raises(ValueError))
开发者ID:fusionapp,项目名称:fusion-util,代码行数:9,代码来源:test_enums.py

示例4: test_must_specify_tags_with_tags_options

 def test_must_specify_tags_with_tags_options(self):
     fn = lambda: safe_parse_arguments(['--fail', 'foo', '--tag'])
     self.assertThat(
         fn,
         MatchesAny(
             raises(RuntimeError('--tag option requires 1 argument')),
             raises(RuntimeError('--tag option requires an argument')),
         )
     )
开发者ID:RayFerr000,项目名称:PLTL,代码行数:9,代码来源:test_output_filter.py

示例5: test_provision_at_cap

 def test_provision_at_cap(self):
     source = model.Source(None, None)
     c = cache.Cache("foo", memory.Store({}), source, maximum=2)
     c.provision(2)
     self.assertThat(lambda: c.provision(1), raises(ValueError))
     # The source was not interrogated for more resources.
     self.assertEqual(['2'], source.provision(1))
     with read_locked(c.store):
         self.assertEqual('0,1', c.store['pool/foo'])
         self.assertThat(lambda:c.store['resource/2'], raises(KeyError))
开发者ID:pombredanne,项目名称:crcache,代码行数:10,代码来源:test_cache.py

示例6: test_TestCommand_get_run_command_outside_setUp_fails

 def test_TestCommand_get_run_command_outside_setUp_fails(self):
     self.dirty()
     ui = UI()
     ui.here = self.tempdir
     command = TestCommand(ui, None)
     self.set_config('[DEFAULT]\ntest_command=foo\n')
     self.assertThat(command.get_run_command, raises(TypeError))
     command.setUp()
     command.cleanUp()
     self.assertThat(command.get_run_command, raises(TypeError))
开发者ID:testing-cabal,项目名称:testrepository,代码行数:10,代码来源:test_testcommand.py

示例7: test_delete

 def test_delete(self):
     s = self.make_store()
     s2 = self.make_store()
     with write_locked(s):
         s['foo'] = 'bar'
     with write_locked(s):
         del s['foo']
     with read_locked(s):
         self.assertThat(lambda:s['foo'], raises(KeyError))
     # The change is immediately visible to other store instances.
     with read_locked(s2):
         self.assertThat(lambda:s2['foo'], raises(KeyError))
开发者ID:pombredanne,项目名称:crcache,代码行数:12,代码来源:test___init__.py

示例8: test_discard_force_ignores_reserve

 def test_discard_force_ignores_reserve(self):
     source = model.Source(None, None)
     c = cache.Cache("foo", memory.Store({}), source, reserve=1)
     c.discard(c.provision(2), force=True)
     self.assertThat(source._calls, MatchesAny(
         Equals([('provision', 2), ('discard', ['0', '1'])]),
         Equals([('provision', 2), ('discard', ['1', '0'])])))
     # The instance should have been unmapped in both directions from the
     # store.
     with read_locked(c.store):
         self.assertEqual('', c.store['pool/foo'])
         self.assertThat(lambda:c.store['resource/0'], raises(KeyError))
         self.assertThat(lambda:c.store['resource/1'], raises(KeyError))
开发者ID:pombredanne,项目名称:crcache,代码行数:13,代码来源:test_cache.py

示例9: test_header_types

 def test_header_types(self):
     """
     Header keys and values must be bytes, not unicode.
     """
     self.assertThat(
         lambda: Request(method='get', url='http://google.com/',
                         headers={u'foo': b'bar'}),
         raises(TypeError("headers key {0!r} is not bytes".format(u'foo')))
         )
     self.assertThat(
         lambda: Request(method='get', url='http://google.com/',
                         headers={b'foo': u'bar'}),
         raises(TypeError("headers value {0!r} is not bytes".format(u'bar')))
         )
开发者ID:radix,项目名称:effreq,代码行数:14,代码来源:test_intent.py

示例10: test_not_set_delta_property_correctly

    def test_not_set_delta_property_correctly(self):
        self.assertThat(
            lambda: deltas.BaseDeltasGenerator(
                source_path=self.source_file, target_path=self.target_file,
                delta_format=None, delta_tool_path=self.delta_tool_path),
            m.raises(deltas.errors.DeltaFormatError)
        )
        exception = self.assertRaises(deltas.errors.DeltaFormatError,
                                      deltas.BaseDeltasGenerator,
                                      source_path=self.source_file,
                                      target_path=self.target_file,
                                      delta_format=None,
                                      delta_tool_path='/usr/bin/xdelta3')
        expected = 'delta_format must be set in subclass!'
        self.assertEqual(str(exception), expected)

        self.assertThat(
            lambda: deltas.BaseDeltasGenerator(
                source_path=self.source_file, target_path=self.target_file,
                delta_format='xdelta3',
                delta_tool_path=None),
            m.raises(deltas.errors.DeltaToolError)
        )
        exception = self.assertRaises(deltas.errors.DeltaToolError,
                                      deltas.BaseDeltasGenerator,
                                      source_path=self.source_file,
                                      target_path=self.target_file,
                                      delta_format='xdelta3',
                                      delta_tool_path=None)
        expected = 'delta_tool_path must be set in subclass!'
        self.assertEqual(str(exception), expected)

        self.assertThat(
            lambda: deltas.BaseDeltasGenerator(
                source_path=self.source_file,
                target_path=self.target_file,
                delta_format='not-defined',
                delta_tool_path='/usr/bin/xdelta3'),
            m.raises(deltas.errors.DeltaFormatOptionError)
        )
        exception = self.assertRaises(deltas.errors.DeltaFormatOptionError,
                                      deltas.BaseDeltasGenerator,
                                      source_path=self.source_file,
                                      target_path=self.target_file,
                                      delta_format='invalid-delta-format',
                                      delta_tool_path=self.delta_tool_path)
        expected = """delta_format must be a option in ['xdelta3'].
for now delta_format='invalid-delta-format'"""
        self.assertEqual(str(exception), expected)
开发者ID:josepht,项目名称:snapcraft,代码行数:49,代码来源:test_deltas.py

示例11: test_discard_multiple

 def test_discard_multiple(self):
     source = model.Source(None, None)
     c = cache.Cache("foo", memory.Store({}), source)
     c.provision(4)
     c.discard(['foo-0', 'foo-2'])
     self.assertEqual(2, c.in_use())
     self.assertEqual(0, c.cached())
     self.assertEqual(
         [('provision', 4), ('discard', ['0', '2'])], source._calls)
     # The instances should have been unmapped in both directions from the
     # store.
     with read_locked(c.store):
         self.assertEqual('1,3', c.store['pool/foo'])
         self.assertThat(lambda:c.store['resource/0'], raises(KeyError))
         self.assertThat(lambda:c.store['resource/2'], raises(KeyError))
开发者ID:pombredanne,项目名称:crcache,代码行数:15,代码来源:test_cache.py

示例12: test_duplicateHandlers

    def test_duplicateHandlers(self):
        """
        Only one handler for an accept type may be specified.
        """
        @implementer(INegotiableResource)
        class _BarJSON(object):
            contentType = b'application/json'
            acceptTypes = [b'application/json']

        self.assertThat(
            partial(ContentTypeNegotiator, [_FooJSON(), _FooJSON()]),
            raises(ValueError))
        self.assertThat(
            partial(ContentTypeNegotiator, [_FooJSON(), _BarJSON()]),
            raises(ValueError))
开发者ID:jerith,项目名称:txspinneret,代码行数:15,代码来源:test_resource.py

示例13: test_rejects_doubledash

 def test_rejects_doubledash(self):
     base = self.useFixture(TempDir()).path
     arg = path.ExistingPathArgument('path')
     self.addCleanup(os.chdir, os.getcwd())
     os.chdir(base)
     with open('--', 'wt') as f:pass
     self.assertThat(lambda: arg.parse(['--']), raises(ValueError))
开发者ID:dstanek,项目名称:testrepository,代码行数:7,代码来源:test_path.py

示例14: test_format_version_4

 def test_format_version_4(self):
     """A hypothetical summary format version 4 is rejected"""
     self.make_bug_summary("1", format_version=4)
     tracker = self.get_tracker()
     self.assertThat(lambda: tracker.getRemoteStatus("1"),
         raises(SummaryVersionError))
     tracker.getRemoteImportance("1")
开发者ID:pombreda,项目名称:UnnaturalCodeFork,代码行数:7,代码来源:test_debbugs.py

示例15: test_none

 def test_none(self):
     """
     Cannot create a task name for ``None``.
     """
     self.assertThat(
         lambda: task_name(None),
         raises(ValueError))
开发者ID:mithrandi,项目名称:eliottree,代码行数:7,代码来源:test_tree.py


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