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


Python pytest.raises方法代码示例

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


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

示例1: test_ask_and_validate

# 需要导入模块: import pytest [as 别名]
# 或者: from pytest import raises [as 别名]
def test_ask_and_validate(io):
    error = "This is not a color!"

    def validator(color):
        if color not in ["white", "black"]:
            raise Exception(error)

        return color

    question = Question("What color was the white horse of Henry IV?", "white")
    question.set_validator(validator)
    question.set_max_attempts(2)

    io.set_input("\nblack\n")
    assert "white" == question.ask(io)
    assert "black" == question.ask(io)

    io.set_input("green\nyellow\norange\n")

    with pytest.raises(Exception) as e:
        question.ask(io)

    assert error == str(e.value) 
开发者ID:sdispater,项目名称:clikit,代码行数:25,代码来源:test_question.py

示例2: test_render_debug_better_error_message_recursion_error_with_multiple_duplicated_frames

# 需要导入模块: import pytest [as 别名]
# 或者: from pytest import raises [as 别名]
def test_render_debug_better_error_message_recursion_error_with_multiple_duplicated_frames():
    io = BufferedIO()
    io.set_verbosity(VERBOSE)

    with pytest.raises(RecursionError) as e:
        first()

    trace = ExceptionTrace(e.value)

    trace.render(io)

    expected = r"...  Previous 2 frames repeated \d+ times".format(
        filename=re.escape(trace._get_relative_file_path(__file__)),
    )

    assert re.search(expected, io.fetch_output()) is not None 
开发者ID:sdispater,项目名称:clikit,代码行数:18,代码来源:test_exception_trace.py

示例3: test_invalid_text_colour

# 需要导入模块: import pytest [as 别名]
# 或者: from pytest import raises [as 别名]
def test_invalid_text_colour():
    """Test valid text colour."""
    sys.modules['spidev'] = mock.MagicMock()
    import unicornhathd
    unicornhathd.setup()

    with pytest.raises(ValueError):
        unicornhathd.set_pixel(0, 0, "Octarine") 
开发者ID:pimoroni,项目名称:unicorn-hat-hd,代码行数:10,代码来源:test_setup.py

示例4: test_model_serializer_mapping_is_none

# 需要导入模块: import pytest [as 别名]
# 或者: from pytest import raises [as 别名]
def test_model_serializer_mapping_is_none(self):
        class EmptyPolymorphicSerializer(PolymorphicSerializer):
            pass

        with pytest.raises(ImproperlyConfigured) as excinfo:
            EmptyPolymorphicSerializer()

        assert str(excinfo.value) == (
            '`EmptyPolymorphicSerializer` is missing a '
            '`EmptyPolymorphicSerializer.model_serializer_mapping` attribute'
        ) 
开发者ID:apirobot,项目名称:django-rest-polymorphic,代码行数:13,代码来源:test_serializers.py

示例5: test_resource_type_field_name_is_not_string

# 需要导入模块: import pytest [as 别名]
# 或者: from pytest import raises [as 别名]
def test_resource_type_field_name_is_not_string(self, mocker):
        class NotStringPolymorphicSerializer(PolymorphicSerializer):
            model_serializer_mapping = mocker.MagicMock
            resource_type_field_name = 1

        with pytest.raises(ImproperlyConfigured) as excinfo:
            NotStringPolymorphicSerializer()

        assert str(excinfo.value) == (
            '`NotStringPolymorphicSerializer.resource_type_field_name` must '
            'be a string'
        ) 
开发者ID:apirobot,项目名称:django-rest-polymorphic,代码行数:14,代码来源:test_serializers.py

示例6: test_filter_codes_ValueError

# 需要导入模块: import pytest [as 别名]
# 或者: from pytest import raises [as 别名]
def test_filter_codes_ValueError():
    """Setting invalid filter codes on the Genome raises a ValueError."""
    with pytest.raises(ValueError):
        genome = Genome()
        genome.filter_codes = ("asdf",) 
开发者ID:EvanKepner,项目名称:mutatest,代码行数:7,代码来源:test_api.py

示例7: test_targets_TypeError

# 需要导入模块: import pytest [as 别名]
# 或者: from pytest import raises [as 别名]
def test_targets_TypeError():
    """Targets with a NoneType source_file raises a TypeError."""
    with pytest.raises(TypeError):
        genome = Genome()
        _ = genome.targets 
开发者ID:EvanKepner,项目名称:mutatest,代码行数:7,代码来源:test_api.py

示例8: test_covered_targets_source_file_TypeError

# 需要导入模块: import pytest [as 别名]
# 或者: from pytest import raises [as 别名]
def test_covered_targets_source_file_TypeError():
    """Targets with a NoneType source_file raises a TypeError."""
    with pytest.raises(TypeError):
        genome = Genome()
        _ = genome.covered_targets 
开发者ID:EvanKepner,项目名称:mutatest,代码行数:7,代码来源:test_api.py

示例9: test_covered_targets_coverage_file_TypeError

# 需要导入模块: import pytest [as 别名]
# 或者: from pytest import raises [as 别名]
def test_covered_targets_coverage_file_TypeError(binop_file):
    """Targets with a NoneType coverage_file but valid source_file raises a TypeError."""
    with pytest.raises(TypeError):
        genome = Genome(binop_file)
        genome.coverage_file = None
        _ = genome.covered_targets 
开发者ID:EvanKepner,项目名称:mutatest,代码行数:8,代码来源:test_api.py

示例10: test_mutate_MutationException

# 需要导入模块: import pytest [as 别名]
# 或者: from pytest import raises [as 别名]
def test_mutate_MutationException(binop_file, mock_LocIdx):
    """Mutate with an invalid operation raises a mutation exception."""
    genome = Genome(binop_file)
    with pytest.raises(MutationException):
        _ = genome.mutate(target_idx=mock_LocIdx, mutation_op="badoperation", write_cache=False) 
开发者ID:EvanKepner,项目名称:mutatest,代码行数:7,代码来源:test_api.py

示例11: test_mutate_ValueError_target

# 需要导入模块: import pytest [as 别名]
# 或者: from pytest import raises [as 别名]
def test_mutate_ValueError_target(binop_file, mock_LocIdx):
    """Mutate with a target_idx not in the targets raises a ValueError."""
    genome = Genome(binop_file)
    with pytest.raises(ValueError):
        _ = genome.mutate(target_idx=mock_LocIdx, mutation_op=ast.Div, write_cache=False) 
开发者ID:EvanKepner,项目名称:mutatest,代码行数:7,代码来源:test_api.py

示例12: test_init_GenomeGroup_raise_TypeError

# 需要导入模块: import pytest [as 别名]
# 或者: from pytest import raises [as 别名]
def test_init_GenomeGroup_raise_TypeError():
    """Initialization with an non-file non-dir raises a TypeError."""
    with pytest.raises(TypeError):
        _ = GenomeGroup("somethingrandom") 
开发者ID:EvanKepner,项目名称:mutatest,代码行数:6,代码来源:test_api.py

示例13: test_GenomeGroup_folder_exception

# 需要导入模块: import pytest [as 别名]
# 或者: from pytest import raises [as 别名]
def test_GenomeGroup_folder_exception():
    """Invalid folders raise a type error."""
    with pytest.raises(TypeError):
        ggrp = GenomeGroup()
        ggrp.add_folder("somethingrandom") 
开发者ID:EvanKepner,项目名称:mutatest,代码行数:7,代码来源:test_api.py

示例14: test_GenomeGroup_key_TypeError

# 需要导入模块: import pytest [as 别名]
# 或者: from pytest import raises [as 别名]
def test_GenomeGroup_key_TypeError(key, binop_file):
    """Values that are not Path type keys raise a type error."""
    with pytest.raises(TypeError):
        ggrp = GenomeGroup()
        ggrp[key] = Genome(binop_file) 
开发者ID:EvanKepner,项目名称:mutatest,代码行数:7,代码来源:test_api.py

示例15: test_GenomeGroup_value_TypeError

# 需要导入模块: import pytest [as 别名]
# 或者: from pytest import raises [as 别名]
def test_GenomeGroup_value_TypeError(value, binop_file):
    """Non-Genome values raise a type error."""
    with pytest.raises(TypeError):
        ggrp = GenomeGroup()
        ggrp[binop_file] = value 
开发者ID:EvanKepner,项目名称:mutatest,代码行数:7,代码来源:test_api.py


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