示例#1
0
def test_expect_external_error_for():
    """Checks that expected errors are skipped when the right options are passed"""
    wrapper = Utils.expect_external_error_for(KeyError, "Key errors for 4", Utils.contains_expected_kwargs(option=4))(sample_method)
    # check that when passing through the expected option the correct error is raised
    assert Utils.method_raises(Utils.ExpectedExternalError)(wrapper)(4)
    assert Utils.method_raises(Utils.ExpectedExternalError)(wrapper)(option=4)
    # check that when passing in different options an exception comes through normally
    assert Utils.method_raises(ValueError)(wrapper)(option=3)
    # check that when passing in different options a return value comes through normally
    assert wrapper(1) == "pigeons"
    assert wrapper(option=1) == "pigeons"
    # check that an assertion is raised if the expected error is not raised
    wrapper = Utils.expect_external_error_for(KeyError, "Key errors for 4", Utils.contains_expected_kwargs(option=3))(sample_method)
    assert Utils.method_raises(AssertionError)(wrapper)(option=3)
    wrapper = Utils.expect_external_error_for(KeyError, "Key errors for 4", Utils.contains_expected_kwargs(option=1))(sample_method)
    assert Utils.method_raises(AssertionError)(wrapper)(option=1)
示例#2
0
def test_skip_test_for():
    """Skips the test when the right options are passed"""
    badgers = {"william": "holland", "eric": "new zealand", "cecily": "paraguay"}
    @Utils.skip_test_for("There is no badger", Utils.contains_expected_kwargs(badger="scott"))
    def find_badger(badger):
        """tries to find the given badger"""
        return badgers[badger]
    assert Utils.method_raises(Utils.Skipped)(find_badger)("scott")
    assert find_badger("william") == "holland"
示例#3
0
def test_expect_external_error_for():
    """Checks that expected errors are skipped when the right options are passed"""
    wrapper = Utils.expect_external_error_for(
        KeyError, "Key errors for 4",
        Utils.contains_expected_kwargs(option=4))(sample_method)
    # check that when passing through the expected option the correct error is raised
    assert Utils.method_raises(Utils.ExpectedExternalError)(wrapper)(4)
    assert Utils.method_raises(Utils.ExpectedExternalError)(wrapper)(option=4)
    # check that when passing in different options an exception comes through normally
    assert Utils.method_raises(ValueError)(wrapper)(option=3)
    # check that when passing in different options a return value comes through normally
    assert wrapper(1) == "pigeons"
    assert wrapper(option=1) == "pigeons"
    # check that an assertion is raised if the expected error is not raised
    wrapper = Utils.expect_external_error_for(
        KeyError, "Key errors for 4",
        Utils.contains_expected_kwargs(option=3))(sample_method)
    assert Utils.method_raises(AssertionError)(wrapper)(option=3)
    wrapper = Utils.expect_external_error_for(
        KeyError, "Key errors for 4",
        Utils.contains_expected_kwargs(option=1))(sample_method)
    assert Utils.method_raises(AssertionError)(wrapper)(option=1)
示例#4
0
def test_skip_test_for():
    """Skips the test when the right options are passed"""
    badgers = {
        "william": "holland",
        "eric": "new zealand",
        "cecily": "paraguay"
    }

    @Utils.skip_test_for("There is no badger",
                         Utils.contains_expected_kwargs(badger="scott"))
    def find_badger(badger):
        """tries to find the given badger"""
        return badgers[badger]

    assert Utils.method_raises(Utils.Skipped)(find_badger)("scott")
    assert find_badger("william") == "holland"