Example #1
0
def must_catch_duplicate_course_by_name(previous):
    return must_catch_ValueError(
            'Attempt to create course with duplicate name {!r} (already exists: {})'.format(
                previous.name,
                previous,
            ),
        )
Example #2
0
def must_catch_duplicate(type_name, name, number):
    return must_catch_ValueError(
        "Attempt to create a {} with duplicate #{} (duplicate of: {})".format(
            type_name,
            number,
            "<{} {!r} #{}>".format(type_name, name, number),
        ), )
Example #3
0
def test_cannot_join_nonexistent_course():
    alice = create_Student('Alice', 1)

    stamp_collecting = 'How to collect stamps for fun & profit'

    with must_catch_ValueError('Failed to find a course named {!r}'.format(stamp_collecting)):
        alice.join_course(stamp_collecting)
Example #4
0
def must_catch_duplicate(type_name, previous):
    return must_catch_ValueError(
            "Attempt to create a {} with duplicate #{} (duplicate of: {})".format(
                type_name,
                previous.number,
                previous,
            ),
        )
Example #5
0
def test_cannot_join_same_course_twice():
    alice = create_Teacher('Alice', 1)

    math = create_Course('Math', 1, alice)

    bob = create_Student('Bob', 2)

    bob.join_course('Math')

    with must_catch_ValueError('{} has already joined course {}; cannot join a second time'.format(bob, math)):
        bob.join_course('Math')
Example #6
0
def test_cannot_create_course_with_duplciate_name():
    alice = create_Teacher('Alice', 1)

    math_by_alice = create_Course('Math', 1, alice)

    bob = create_Teacher('Bob', 2)

    with must_catch_ValueError(
            'Attempt to create course with duplicate name {!r} (already exists: {})'.format(
                'Math',
                math_by_alice
            ),
    ):
        math_by_bob = create_Course('Math', 2, bob)
Example #7
0
def test_cannot_learn_fact_with_same_name_twice():
    alice = create_Student('Alice', 1)

    false_fact__1_plus_1__is__1 = create_false_fact('What is 1+1?', 'One')
    true_fact__1_plus_1__is__2  = create_true_fact ('What is 1+1?', 'Two')

    alice.teach(false_fact__1_plus_1__is__1)

    with must_catch_ValueError(
            '{} already knows {}; cannot be taught {}'.format(
                alice,
                false_fact__1_plus_1__is__1,
                true_fact__1_plus_1__is__2,
            ),
    ):
        alice.teach(true_fact__1_plus_1__is__2)
Example #8
0
 def raise_wrong_exception():
     with must_catch_ValueError('Correct'):
         raise wrong_exception
Example #9
0
 def fail_to_raise_a_ValueError():
     with must_catch_ValueError('Oops'):
         pass
Example #10
0
def test_must_catch_ValueError__positive():
    with must_catch_ValueError('Oops'):
        raise ValueError('Oops')
Example #11
0
def attempt_to_load_a_set_of_people_that_includes_an_invalid_person_type(context, invalid_person_type):
    with must_catch_ValueError(
            'unknown person type: {!r}'.format(invalid_person_type)
    ) as context.caught:
        for [i, [is_teacher, name, number]] in enumerate(iterate_students_and_teachers(context)):
            create_student_or_teacher__and__print(i, is_teacher, name, number)