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


Python tools.assert_raises_regexp方法代码示例

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


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

示例1: assert_raises_regex

# 需要导入模块: from nose import tools [as 别名]
# 或者: from nose.tools import assert_raises_regexp [as 别名]
def assert_raises_regex(expected_exception, expected_regexp,
                                callable_obj=None, *args, **kwargs):
            """Helper function to check for message patterns in exceptions"""

            not_raised = False
            try:
                callable_obj(*args, **kwargs)
                not_raised = True
            except Exception as e:
                error_message = str(e)
                if not re.compile(expected_regexp).search(error_message):
                    raise AssertionError("Error message should match pattern "
                                         "%r. %r does not." %
                                         (expected_regexp, error_message))
            if not_raised:
                raise AssertionError("Should have raised %r" %
                                     expected_exception(expected_regexp)) 
开发者ID:bbfamily,项目名称:abu,代码行数:19,代码来源:testing.py

示例2: test_percentile_few_points

# 需要导入模块: from nose import tools [as 别名]
# 或者: from nose.tools import assert_raises_regexp [as 别名]
def test_percentile_few_points():
    with nt.assert_raises_regexp(StatisticsError, "few data points \(6\) for 1th"):
        mm.percentile([1.5, 2.5, 2.5, 2.75, 3.25, 4.75], 1) 
开发者ID:avalente,项目名称:appmetrics,代码行数:5,代码来源:test_statistics.py

示例3: test_percentile_empty

# 需要导入模块: from nose import tools [as 别名]
# 或者: from nose.tools import assert_raises_regexp [as 别名]
def test_percentile_empty():
    with nt.assert_raises_regexp(StatisticsError, "few data points \(0\) for 90th"):
        mm.percentile([], 90) 
开发者ID:avalente,项目名称:appmetrics,代码行数:5,代码来源:test_statistics.py

示例4: test_get_histogram_few_points

# 需要导入模块: from nose import tools [as 别名]
# 或者: from nose.tools import assert_raises_regexp [as 别名]
def test_get_histogram_few_points():
    with nt.assert_raises_regexp(StatisticsError, "few data points \(1\) for get_histogram"):
        mm.get_histogram([1.5]) 
开发者ID:avalente,项目名称:appmetrics,代码行数:5,代码来源:test_statistics.py

示例5: assert_raises_regex

# 需要导入模块: from nose import tools [as 别名]
# 或者: from nose.tools import assert_raises_regexp [as 别名]
def assert_raises_regex(expected, regexp, callable_obj=None, *args, **kwargs):
            context = AssertRaisesContext(expected, regexp)
            if callable_obj is None:
                return context
            with context:
                callable_obj(*args, **kwargs) 
开发者ID:dfunckt,项目名称:django-connections,代码行数:8,代码来源:__init__.py

示例6: test_config_initialization

# 需要导入模块: from nose import tools [as 别名]
# 或者: from nose.tools import assert_raises_regexp [as 别名]
def test_config_initialization(patched_func):
    cwd = os.getcwd()
    test_folder = os.path.join(cwd, 'test')
    # Test normal case
    config.initialize_config(test_folder)
    assert os.path.isdir(test_folder)
    assert not os.path.exists(os.path.join(test_folder, 'verb_aliases'))
    # Assert a second invocation is fine
    config.initialize_config(test_folder)
    shutil.rmtree(test_folder)
    # Test failure with file for target config path
    with open(test_folder, 'w') as f:
        f.write('this will cause a RuntimeError')
    with assert_raises_regexp(RuntimeError, "The catkin config directory"):
        config.initialize_config(test_folder) 
开发者ID:catkin,项目名称:catkin_tools,代码行数:17,代码来源:test_config.py

示例7: test_verb_alias_config_initialization

# 需要导入模块: from nose import tools [as 别名]
# 或者: from nose.tools import assert_raises_regexp [as 别名]
def test_verb_alias_config_initialization():
    cwd = os.getcwd()
    test_folder = os.path.join(cwd, 'test')
    # Test target directory does not exist failure
    with assert_raises_regexp(RuntimeError, "Cannot initialize verb aliases because catkin configuration path"):
        config.initialize_verb_aliases(test_folder)
    # Test normal case
    os.makedirs(test_folder)
    config.initialize_verb_aliases(test_folder)
    assert os.path.isdir(test_folder)
    assert os.path.isdir(os.path.join(test_folder, 'verb_aliases'))
    defaults_path = os.path.join(test_folder, 'verb_aliases', '00-default-aliases.yaml')
    assert os.path.isfile(defaults_path)
    # Assert a second invocation is fine
    config.initialize_verb_aliases(test_folder)
    # Check that replacement of defaults works
    with open(defaults_path, 'w') as f:
        f.write("This should be overwritten (simulation of update needed)")
    with redirected_stdio() as (out, err):
        config.initialize_verb_aliases(test_folder)
    assert "Warning, builtin verb aliases at" in out.getvalue(), out.getvalue()
    shutil.rmtree(test_folder)
    # Check failure from verb aliases folder existing as a file
    os.makedirs(test_folder)
    with open(os.path.join(test_folder, 'verb_aliases'), 'w') as f:
        f.write("this will cause a RuntimeError")
    with assert_raises_regexp(RuntimeError, "The catkin verb aliases config directory"):
        config.initialize_verb_aliases(test_folder)
    shutil.rmtree(test_folder) 
开发者ID:catkin,项目名称:catkin_tools,代码行数:31,代码来源:test_config.py

示例8: test_parse_exception_missing_paren

# 需要导入模块: from nose import tools [as 别名]
# 或者: from nose.tools import assert_raises_regexp [as 别名]
def test_parse_exception_missing_paren():
    """TEST 1.7: The proper exception should be raised if the expression
    is incomplete."""

    with assert_raises_regexp(DiyLangError, 'Incomplete expression'):
        parse('(foo (bar x y)') 
开发者ID:kvalle,项目名称:diy-lang,代码行数:8,代码来源:test_1_parsing.py

示例9: test_parse_exception_extra_paren

# 需要导入模块: from nose import tools [as 别名]
# 或者: from nose.tools import assert_raises_regexp [as 别名]
def test_parse_exception_extra_paren():
    """TEST 1.8: Another exception is raised if the expression is too large.

    The parse function expects to receive only one single expression. Anything
    more than this, should result in the proper exception."""

    with assert_raises_regexp(DiyLangError, 'Expected EOF'):
        parse('(foo (bar x y)))') 
开发者ID:kvalle,项目名称:diy-lang,代码行数:10,代码来源:test_1_parsing.py

示例10: test_find_matching_paren_throws_exception_on_no_closing_paren

# 需要导入模块: from nose import tools [as 别名]
# 或者: from nose.tools import assert_raises_regexp [as 别名]
def test_find_matching_paren_throws_exception_on_no_closing_paren():
    """The function should raise error when there is no matching paren to be
    found"""

    with assert_raises_regexp(DiyLangError, "Incomplete expression"):
        find_matching_paren("string (without closing paren", 7)

# Tests for unparse in parser.py 
开发者ID:kvalle,项目名称:diy-lang,代码行数:10,代码来源:test_provided_code.py

示例11: test_lookup_on_missing_raises_exception

# 需要导入模块: from nose import tools [as 别名]
# 或者: from nose.tools import assert_raises_regexp [as 别名]
def test_lookup_on_missing_raises_exception():
    """TEST 4.2: When looking up an undefined symbol, an error should be raised.

    The error message should contain the relevant symbol, and inform that it
    has not been defined.
    """

    with assert_raises_regexp(DiyLangError, "my-missing-var"):
        empty_env = Environment()
        empty_env.lookup("my-missing-var") 
开发者ID:kvalle,项目名称:diy-lang,代码行数:12,代码来源:test_4_working_with_variables_and_environments.py

示例12: test_redefine_variables_illegal

# 需要导入模块: from nose import tools [as 别名]
# 或者: from nose.tools import assert_raises_regexp [as 别名]
def test_redefine_variables_illegal():
    """TEST 4.7: Variables can only be defined once.

    Setting a variable in an environment where it is already defined should
    result in an appropriate error.
    """

    env = Environment({"foo": 1})
    with assert_raises_regexp(DiyLangError, "already defined"):
        env.set("foo", 2) 
开发者ID:kvalle,项目名称:diy-lang,代码行数:12,代码来源:test_4_working_with_variables_and_environments.py

示例13: test_define_with_wrong_number_of_arguments

# 需要导入模块: from nose import tools [as 别名]
# 或者: from nose.tools import assert_raises_regexp [as 别名]
def test_define_with_wrong_number_of_arguments():
    """TEST 4.11: Defines should have exactly two arguments, or raise an error.

    This type of check could benefit the other forms we implement as well,
    and you might want to add them elsewhere. It quickly get tiresome to
    test for this however, so the tests won't require you to.
    """

    with assert_raises_regexp(DiyLangError, "Wrong number of arguments"):
        evaluate(parse("(define x)"), Environment())

    with assert_raises_regexp(DiyLangError, "Wrong number of arguments"):
        evaluate(parse("(define x 1 2)"), Environment()) 
开发者ID:kvalle,项目名称:diy-lang,代码行数:15,代码来源:test_4_working_with_variables_and_environments.py

示例14: test_define_with_non_symbol_as_variable

# 需要导入模块: from nose import tools [as 别名]
# 或者: from nose.tools import assert_raises_regexp [as 别名]
def test_define_with_non_symbol_as_variable():
    """TEST 4.12: Defines require the first argument to be a symbol."""

    with assert_raises_regexp(DiyLangError, "not a symbol"):
        evaluate(parse("(define #t 42)"), Environment()) 
开发者ID:kvalle,项目名称:diy-lang,代码行数:7,代码来源:test_4_working_with_variables_and_environments.py

示例15: test_get_verb_aliases

# 需要导入模块: from nose import tools [as 别名]
# 或者: from nose.tools import assert_raises_regexp [as 别名]
def test_get_verb_aliases():
    cwd = os.getcwd()
    test_folder = os.path.join(cwd, 'test')
    # Test failure case where config folder does not exist
    with assert_raises_regexp(RuntimeError, "Cannot get verb aliases because the catkin config path"):
        config.get_verb_aliases(test_folder)
    # Test failure case where aliases folder does not exist
    with mock.patch('catkin_tools.config.initialize_verb_aliases'):
        config.initialize_config(test_folder)
    with assert_raises_regexp(RuntimeError, "Cannot get verb aliases because the verb aliases config path"):
        config.get_verb_aliases(test_folder)
    shutil.rmtree(test_folder)
    # Test the normal case
    config.initialize_config(test_folder)
    aliases = config.get_verb_aliases(test_folder)
    assert 'b' in aliases
    assert aliases['b'] == ['build']
    # Test a custom file
    base_path = os.path.join(test_folder, 'verb_aliases')
    with open(os.path.join(base_path, '01-my-custom-aliases.yaml'), 'w') as f:
        f.write("""\
b: build --isolate-devel
ls: null
""")
    aliases = config.get_verb_aliases(test_folder)
    assert 'b' in aliases
    assert aliases['b'] == ['build', '--isolate-devel'], aliases['b']
    assert 'ls' not in aliases
    # Test a bad alias files
    bad_path = os.path.join(base_path, '02-bad.yaml')
    with open(bad_path, 'w') as f:
        f.write("""\
- foo
- bar
""")
    with assert_raises_regexp(RuntimeError, "Invalid alias file"):
        config.get_verb_aliases(test_folder)
    os.remove(bad_path)
    with open(bad_path, 'w') as f:
        f.write("""\
null: foo
""")
    with assert_raises_regexp(RuntimeError, "Invalid alias in file"):
        config.get_verb_aliases(test_folder)
    os.remove(bad_path)
    with open(bad_path, 'w') as f:
        f.write("""\
foo: 13.4
""")
    with assert_raises_regexp(RuntimeError, "Invalid alias expansion in file"):
        config.get_verb_aliases(test_folder)
    os.remove(bad_path)
    # Test with an empty custom file
    empty_path = os.path.join(base_path, '02-my-empty.yaml')
    with open(empty_path, 'a') as f:
        os.utime(empty_path, None)
    aliases = config.get_verb_aliases(test_folder) 
开发者ID:catkin,项目名称:catkin_tools,代码行数:59,代码来源:test_config.py


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