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


Python six.assertRaisesRegex方法代码示例

本文整理汇总了Python中six.assertRaisesRegex方法的典型用法代码示例。如果您正苦于以下问题:Python six.assertRaisesRegex方法的具体用法?Python six.assertRaisesRegex怎么用?Python six.assertRaisesRegex使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在six的用法示例。


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

示例1: test_validate_params

# 需要导入模块: import six [as 别名]
# 或者: from six import assertRaisesRegex [as 别名]
def test_validate_params(self):
        """Test that `KerasImageFileEstimator._validateParams` method works as expected"""
        kifest = KerasImageFileEstimator()

        # should raise an error to define required parameters
        # assuming at least one param without default value
        six.assertRaisesRegex(self, ValueError, 'defined', kifest._validateParams, {})
        kifest.setParams(imageLoader=_load_image_from_uri, inputCol='c1', labelCol='c2')
        kifest.setParams(modelFile='/path/to/file.ext')

        # should raise an error to define or tune parameters
        # assuming at least one tunable param without default value
        six.assertRaisesRegex(self, ValueError, 'tuned', kifest._validateParams, {})
        kifest.setParams(kerasOptimizer='adam', kerasLoss='mse', kerasFitParams={})
        kifest.setParams(outputCol='c3', outputMode='vector')

        # should raise an error to not override
        six.assertRaisesRegex(
            self, ValueError, 'not tuned', kifest._validateParams, {kifest.imageLoader: None})

        # should pass test on supplying all parameters
        self.assertTrue(kifest._validateParams({})) 
开发者ID:databricks,项目名称:spark-deep-learning,代码行数:24,代码来源:test_keras_estimators.py

示例2: test_get_pull_request

# 需要导入模块: import six [as 别名]
# 或者: from six import assertRaisesRegex [as 别名]
def test_get_pull_request(self):
        """Tests for _get_pull_request."""
        # Simple case: get the existing PR from the existing repo.
        result = pss._get_pull_request(self.repo, "3")
        self.assertEqual(result.id, 3)

        # PR that doesn't exist.
        six.assertRaisesRegex(
            self,
            PagureEvException,
            r"Pull-Request '2' not found",
            pss._get_pull_request,
            self.repo,
            "2",
        )

        # PR from a project with no PR tracker.
        six.assertRaisesRegex(
            self,
            PagureEvException,
            r"No pull-request tracker found",
            pss._get_pull_request,
            self.repo2,
            "1",
        ) 
开发者ID:Pagure,项目名称:pagure,代码行数:27,代码来源:test_stream_server.py

示例3: test_get_obj_from_path

# 需要导入模块: import six [as 别名]
# 或者: from six import assertRaisesRegex [as 别名]
def test_get_obj_from_path(self):
        """Tests for get_obj_from_path."""
        # Simple issue case.
        result = pss.get_obj_from_path("/test/issue/1")
        self.assertEqual(result.id, 1)

        # Simple PR case.
        result = pss.get_obj_from_path("/test/pull-request/3")
        self.assertEqual(result.id, 3)

        # Non-existent repo.
        six.assertRaisesRegex(
            self,
            PagureEvException,
            r"Project 'foo' not found",
            pss.get_obj_from_path,
            "/foo/issue/1",
        )

        # NOTE: we cannot test the 'Invalid object provided' exception
        # as it's a backup (current code will never hit it) 
开发者ID:Pagure,项目名称:pagure,代码行数:23,代码来源:test_stream_server.py

示例4: testParseBadEnumValue

# 需要导入模块: import six [as 别名]
# 或者: from six import assertRaisesRegex [as 别名]
def testParseBadEnumValue(self, message_module):
    message = message_module.TestAllTypes()
    text = 'optional_nested_enum: BARR'
    six.assertRaisesRegex(self, 
        text_format.ParseError,
        (r'1:23 : Enum type "\w+.TestAllTypes.NestedEnum" '
         r'has no value named BARR.'),
        text_format.Parse, text, message)

    message = message_module.TestAllTypes()
    text = 'optional_nested_enum: 100'
    six.assertRaisesRegex(self, 
        text_format.ParseError,
        (r'1:23 : Enum type "\w+.TestAllTypes.NestedEnum" '
         r'has no value with number 100.'),
        text_format.Parse, text, message) 
开发者ID:sklearn-theano,项目名称:sklearn-theano,代码行数:18,代码来源:text_format_test.py

示例5: check_type_mismatch

# 需要导入模块: import six [as 别名]
# 或者: from six import assertRaisesRegex [as 别名]
def check_type_mismatch(self, x_data, retain):
        xp = backend.get_array_module(x_data)

        class DummyFunction(chainer.Function):
            label = 'dummy_function'

            def forward(self, inputs):
                if not retain:
                    self.retain_inputs(())
                return xp.array(1, np.float32),

            def backward(self, inputs, grads):
                return [1]

        x = chainer.Variable(x_data)
        y = DummyFunction()(x)
        with six.assertRaisesRegex(self, TypeError, 'dummy_function'):
            y.backward() 
开发者ID:chainer,项目名称:chainer,代码行数:20,代码来源:test_variable.py

示例6: check_dtype_mismatch

# 需要导入模块: import six [as 别名]
# 或者: from six import assertRaisesRegex [as 别名]
def check_dtype_mismatch(self, x_data, retain):
        xp = backend.get_array_module(x_data)

        class DummyFunction(chainer.Function):
            label = 'dummy_function'

            def forward(self, inputs):
                if not retain:
                    self.retain_inputs(())
                return xp.array(1, np.float32),

            def backward(self, inputs, grads):
                return xp.array([1], np.int32),

        x = chainer.Variable(x_data)
        y = DummyFunction()(x)
        with six.assertRaisesRegex(self, TypeError, 'dummy_function'):
            y.backward() 
开发者ID:chainer,项目名称:chainer,代码行数:20,代码来源:test_variable.py

示例7: check_shape_mismatch

# 需要导入模块: import six [as 别名]
# 或者: from six import assertRaisesRegex [as 别名]
def check_shape_mismatch(self, x_data, retain):
        xp = backend.get_array_module(x_data)

        class DummyFunction(chainer.Function):
            label = 'dummy_function'

            def forward(self, inputs):
                if not retain:
                    self.retain_inputs(())
                return xp.array(1, np.float32),

            def backward(self, inputs, grads):
                return xp.array([1, 2], np.float32),

        x = chainer.Variable(x_data)
        y = DummyFunction()(x)
        with six.assertRaisesRegex(self, ValueError, 'dummy_function'):
            y.backward() 
开发者ID:chainer,项目名称:chainer,代码行数:20,代码来源:test_variable.py

示例8: test_do_not_create_insecure_secret_keys

# 需要导入模块: import six [as 别名]
# 或者: from six import assertRaisesRegex [as 别名]
def test_do_not_create_insecure_secret_keys(self, mocks, mock_consul):
        """
        Test that if we have a brand-new instance with no appservers, we refuse to create insecure
        keys for those appservers if we don't have a secure secret key for the instance.
        """
        instance = OpenEdXInstanceFactory()
        instance.secret_key_b64encoded = ''
        instance.save()

        expected_error_string = re.escape(
            'Attempted to create secret key for instance {}, but no master key present.'.format(instance)
        )

        # Six provides a compatibility method for assertRaisesRegex, since the method
        # is named differently between Py2k and Py3k.
        with six.assertRaisesRegex(self, ValueError, expected_error_string):
            instance.spawn_appserver() 
开发者ID:open-craft,项目名称:opencraft,代码行数:19,代码来源:test_openedx_secret_key_mixins.py

示例9: test_quit_problems

# 需要导入模块: import six [as 别名]
# 或者: from six import assertRaisesRegex [as 别名]
def test_quit_problems(self):
        comm.start_cluster('127.0.0.1', 7100)
        comm.join_cluster('127.0.0.1', 7100, '127.0.0.1', 7101)
        comm.replicate('127.0.0.1', 7100, '127.0.0.1', 7102)
        time.sleep(1)

        rc = StrictRedisCluster(
            startup_nodes=[{
                'host': '127.0.0.1',
                'port': 7100
            }],
            decode_responses=True)

        for i in range(20):
            rc.set('key_%s' % i, 'value_%s' % i)
        for i in range(20):
            self.assertEqual('value_%s' % i, rc.get('key_%s' % i))

        nodes = base.list_nodes('127.0.0.1', 7100)
        self.assertEqual(3, len(nodes))
        self.assertEqual(
            list(range(8192)), nodes[('127.0.0.1', 7101)].assigned_slots)
        self.assertEqual(
            list(range(8192, 16384)), nodes[('127.0.0.1',
                                             7100)].assigned_slots)
        for i in range(20):
            rc.delete('key_%s' % i)

        six.assertRaisesRegex(self, ValueError,
                              '^The master still has slaves$',
                              comm.quit_cluster, '127.0.0.1', 7100)
        comm.quit_cluster('127.0.0.1', 7102)
        comm.quit_cluster('127.0.0.1', 7101)
        six.assertRaisesRegex(self, ValueError, '^This is the last node',
                              comm.quit_cluster, '127.0.0.1', 7100)
        comm.shutdown_cluster('127.0.0.1', 7100) 
开发者ID:projecteru,项目名称:redis-trib.py,代码行数:38,代码来源:replicates.py

示例10: test_get_issue

# 需要导入模块: import six [as 别名]
# 或者: from six import assertRaisesRegex [as 别名]
def test_get_issue(self):
        """Tests for _get_issue."""
        # Simple case: get the existing issue from the existing repo.
        result = pss._get_issue(self.repo, "1")
        self.assertEqual(result.id, 1)

        # Issue that doesn't exist.
        six.assertRaisesRegex(
            self,
            PagureEvException,
            r"Issue '3' not found",
            pss._get_issue,
            self.repo,
            "3",
        )

        # Private issue (for now we don't handle auth).
        six.assertRaisesRegex(
            self,
            PagureEvException,
            r"issue is private",
            pss._get_issue,
            self.repo,
            "2",
        )

        # Issue from a project with no issue tracker.
        six.assertRaisesRegex(
            self,
            PagureEvException,
            r"No issue tracker found",
            pss._get_issue,
            self.repo2,
            "1",
        ) 
开发者ID:Pagure,项目名称:pagure,代码行数:37,代码来源:test_stream_server.py

示例11: test_compute_create_time_fail

# 需要导入模块: import six [as 别名]
# 或者: from six import assertRaisesRegex [as 别名]
def test_compute_create_time_fail(self, unused_name, age):
    del unused_name
    with six.assertRaisesRegex(self, ValueError, 'Unable to parse age string'):
      _ = param_util.age_to_create_time(age) 
开发者ID:DataBiosphere,项目名称:dsub,代码行数:6,代码来源:param_util_test.py

示例12: test_timeout_in_seconds_fail

# 需要导入模块: import six [as 别名]
# 或者: from six import assertRaisesRegex [as 别名]
def test_timeout_in_seconds_fail(self, unused_name, timeout):
    del unused_name
    with six.assertRaisesRegex(self, ValueError, 'Unable to parse interval'):
      _ = param_util.timeout_in_seconds(timeout) 
开发者ID:DataBiosphere,项目名称:dsub,代码行数:6,代码来源:param_util_test.py

示例13: test_log_interval_in_seconds_fail

# 需要导入模块: import six [as 别名]
# 或者: from six import assertRaisesRegex [as 别名]
def test_log_interval_in_seconds_fail(self, unused_name, log_interval):
    del unused_name
    with six.assertRaisesRegex(self, ValueError, 'Unable to parse interval'):
      _ = param_util.log_interval_in_seconds(log_interval) 
开发者ID:DataBiosphere,项目名称:dsub,代码行数:6,代码来源:param_util_test.py

示例14: test_output_val_err

# 需要导入模块: import six [as 别名]
# 或者: from six import assertRaisesRegex [as 别名]
def test_output_val_err(self, unused_name, recursive, uri, regex):
    del unused_name
    file_param_util = param_util.OutputFileParamUtil('output')
    with six.assertRaisesRegex(self, ValueError, regex):
      file_param_util.parse_uri(uri, recursive) 
开发者ID:DataBiosphere,项目名称:dsub,代码行数:7,代码来源:param_util_test.py

示例15: test_file_provider_err

# 需要导入模块: import six [as 别名]
# 或者: from six import assertRaisesRegex [as 别名]
def test_file_provider_err(self, unused_name, uri, regex):
    del unused_name
    file_param_util = param_util.OutputFileParamUtil('output')
    with six.assertRaisesRegex(self, ValueError, regex):
      file_param_util.parse_file_provider(uri) 
开发者ID:DataBiosphere,项目名称:dsub,代码行数:7,代码来源:param_util_test.py


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