Example #1
0
def test_can_trap_errors_fails_if_error_does_not_happen():
    class_name = "%s.RuntimeError" % RuntimeError.__module__
    err = expect.error_to_happen(RuntimeError)

    try:
        with err:
            pass
    except AssertionError:
        error = sys.exc_info()[1]
        expect(error).to_have_an_error_message_of(
            'Expected "%s" to happen but no errors happened during execution of with block.' % class_name
        )
    else:
        expect.not_to_be_here()

    try:
        with expect.error_to_happen(RuntimeError):
            pass
    except AssertionError:
        error = sys.exc_info()[1]
        expect(error).to_have_an_error_message_of(
            'Expected "%s" to happen but no errors happened during execution of with block.' % class_name
        )
    else:
        expect.not_to_be_here()
Example #2
0
def test_expect_not_to_be_here_with_message():
    try:
        expect.not_to_be_here("qweqwe")
    except AssertionError:
        err = sys.exc_info()[1]
        expect(err).to_be_an_error()
        expect(err).to_be_an_error_like(AssertionError)
        expect(err).to_have_an_error_message_of("Should not have gotten this far (qweqwe).")
    else:
        assert False, "Should not have gotten this far."
Example #3
0
def test_can_trap_errors_but_fail_due_to_message():
    try:
        with expect.not_error_to_happen(RuntimeError, message="qweqwe"):
            raise RuntimeError("something is wrong")
    except AssertionError:
        err = sys.exc_info()[1]
        expect(str(err)).to_include(
            'to have a message of "qweqwe", but the actual error was "something is wrong".'
        )
        return

    expect.not_to_be_here()
Example #4
0
def test_can_trap_errors_but_fail_due_to_type():
    try:
        with expect.not_error_to_happen(RuntimeError):
            raise ValueError("something is wrong")
    except AssertionError:
        err = sys.exc_info()[1]
        expect(str(err)).to_include(
            'ValueError" happened during execution of with block.'
        )
        return

    expect.not_to_be_here()
Example #5
0
def test_can_NOT_trap_errors():
    try:
        with expect.not_error_to_happen(RuntimeError):
            raise RuntimeError("something is wrong")
    except AssertionError:
        err = sys.exc_info()[1]
        expect(str(err)).to_include(
            'not to happen but it happened during execution of with block.'
        )
        return

    expect.not_to_be_here()
Example #6
0
def test_can_trap_errors_fails_if_wrong_error():
    class_name = "%s.RuntimeError" % RuntimeError.__module__
    value_class_name = "%s.ValueError" % ValueError.__module__
    err = expect.error_to_happen(RuntimeError)

    try:
        with err:
            raise ValueError("something else entirely")
    except AssertionError:
        error = sys.exc_info()[1]
        expect(error).to_have_an_error_message_of('Expected "%s" to happen but "%s" happened during execution of with block.' % (class_name, value_class_name))
    else:
        expect.not_to_be_here()
Example #7
0
def test_can_trap_errors_fails_if_wrong_error_message():
    class_name = "%s.ValueError" % ValueError.__module__
    err = expect.error_to_happen(ValueError, message="Woot?")

    try:
        with err:
            raise ValueError("something else entirely")
    except AssertionError:
        error = sys.exc_info()[1]
        expect(error).to_have_an_error_message_of(
            'Expected "%s" to have a message of "Woot?", but the actual error was "something else entirely".' % class_name
        )
    else:
        expect.not_to_be_here()
Example #8
0
 def put_override(self, path, contents):
     expect.not_to_be_here()
Example #9
0
 def test_can_run_async(self):
     expect.not_to_be_here()