[Chaitana's Colossal Coaster] Task 4 advice requested

We are stumped again in determining the error condition we need to test for in order to pass the test variants. Looks like we need to shake the tree, again. I’d really appreciate some advice on this question, please/thanks.

remove_the_mean_person
def remove_the_mean_person(queue, person_name):
    """Remove the mean person from the queue by the provided name.
    :param queue: list - names in the queue.
    :param person_name: str - name of mean person.
    :return: list - queue update with the mean persons name removed.
    """
    if not isinstance(queue, list):
        raise TypeError('Input must be a list')
    queue = queue.remove(person_name)
    return queue

Task 4 Mean person in the queue

Test 4
* Failed ListMethods > remove the mean person

Code Run

test_data = [(['Natasha', 'Steve', 'Ultron', 'Wanda', 'Rocket'], 'Ultron'),
             (['Natasha', 'Steve', 'Wanda', 'Rocket', 'Ultron'], 'Ultron'),
             (['Ultron', 'Natasha', 'Steve', 'Wanda', 'Rocket'], 'Ultron'),

]
result_data = [['Natasha', 'Steve', 'Wanda', 'Rocket'],
               ['Natasha', 'Steve', 'Wanda', 'Rocket'],
               ['Natasha', 'Steve', 'Wanda', 'Rocket']]

for variant, (params, expected) in enumerate(zip(test_data, result_data), start=1):

    # Deepcopy() is needed here because the task expects the input lists to be mutated.
    # That mutation wrecks havoc with the verification and error messaging.
    queue, person_name = deepcopy(params)

    with self.subTest(f'variation #{variant}',
                      queue=queue,
                      person_name=person_name,
                      expected=expected):

        actual_result = remove_the_mean_person(*params)
        error_message = (f'Called remove_the_mean_person{queue, person_name}. '
                         f'The function returned {actual_result}, but '
                         f'The tests expected {expected} when removing '
                         f'{person_name} from the queue.')

        self.assertListEqual(actual_result, expected, msg=error_message)

Test Failure

One or more variations of this test failed. Details can be found under each [variant#].
Test 5
  • Failed … [variation #1]
Code Run

test_data = [(['Natasha', 'Steve', 'Ultron', 'Wanda', 'Rocket'], 'Ultron'),
             (['Natasha', 'Steve', 'Wanda', 'Rocket', 'Ultron'], 'Ultron'),
             (['Ultron', 'Natasha', 'Steve', 'Wanda', 'Rocket'], 'Ultron'),

]
result_data = [['Natasha', 'Steve', 'Wanda', 'Rocket'],
               ['Natasha', 'Steve', 'Wanda', 'Rocket'],
               ['Natasha', 'Steve', 'Wanda', 'Rocket']]

for variant, (params, expected) in enumerate(zip(test_data, result_data), start=1):

    # Deepcopy() is needed here because the task expects the input lists to be mutated.
    # That mutation wrecks havoc with the verification and error messaging.
    queue, person_name = deepcopy(params)

    with self.subTest(f'variation #{variant}',
                      queue=queue,
                      person_name=person_name,
                      expected=expected):

        actual_result = remove_the_mean_person(*params)
        error_message = (f'Called remove_the_mean_person{queue, person_name}. '
                         f'The function returned {actual_result}, but '
                         f'The tests expected {expected} when removing '
                         f'{person_name} from the queue.')

        self.assertListEqual(actual_result, expected, msg=error_message)

Test Failure

AssertionError: First sequence is not a list: None
Test 6
  • Failed … [variation #2]

Code Run


test_data = [(['Natasha', 'Steve', 'Ultron', 'Wanda', 'Rocket'], 'Ultron'),
             (['Natasha', 'Steve', 'Wanda', 'Rocket', 'Ultron'], 'Ultron'),
             (['Ultron', 'Natasha', 'Steve', 'Wanda', 'Rocket'], 'Ultron'),

]
result_data = [['Natasha', 'Steve', 'Wanda', 'Rocket'],
               ['Natasha', 'Steve', 'Wanda', 'Rocket'],
               ['Natasha', 'Steve', 'Wanda', 'Rocket']]

for variant, (params, expected) in enumerate(zip(test_data, result_data), start=1):

    # Deepcopy() is needed here because the task expects the input lists to be mutated.
    # That mutation wrecks havoc with the verification and error messaging.
    queue, person_name = deepcopy(params)

    with self.subTest(f'variation #{variant}',
                      queue=queue,
                      person_name=person_name,
                      expected=expected):

        actual_result = remove_the_mean_person(*params)
        error_message = (f'Called remove_the_mean_person{queue, person_name}. '
                         f'The function returned {actual_result}, but '
                         f'The tests expected {expected} when removing '
                         f'{person_name} from the queue.')

        self.assertListEqual(actual_result, expected, msg=error_message)

Test Failure

AssertionError: First sequence is not a list: None
Test 7
  • Failed … [variation #3]

Code Run


test_data = [(['Natasha', 'Steve', 'Ultron', 'Wanda', 'Rocket'], 'Ultron'),
             (['Natasha', 'Steve', 'Wanda', 'Rocket', 'Ultron'], 'Ultron'),
             (['Ultron', 'Natasha', 'Steve', 'Wanda', 'Rocket'], 'Ultron'),

]
result_data = [['Natasha', 'Steve', 'Wanda', 'Rocket'],
               ['Natasha', 'Steve', 'Wanda', 'Rocket'],
               ['Natasha', 'Steve', 'Wanda', 'Rocket']]

for variant, (params, expected) in enumerate(zip(test_data, result_data), start=1):

    # Deepcopy() is needed here because the task expects the input lists to be mutated.
    # That mutation wrecks havoc with the verification and error messaging.
    queue, person_name = deepcopy(params)

    with self.subTest(f'variation #{variant}',
                      queue=queue,
                      person_name=person_name,
                      expected=expected):

        actual_result = remove_the_mean_person(*params)
        error_message = (f'Called remove_the_mean_person{queue, person_name}. '
                         f'The function returned {actual_result}, but '
                         f'The tests expected {expected} when removing '
                         f'{person_name} from the queue.')

        self.assertListEqual(actual_result, expected, msg=error_message)

Test Failure

AssertionError: First sequence is not a list: None

What is this line supposed to do? What does it actually do? Can you test that somehow (ideally in a REPL).

1 Like
queue = ['Natasha', 'Steve', 'Ultron', 'Wanda', 'Rocket']
remove_the_mean_person(queue, 'Ultron')
print (queue)
['Natasha', 'Steve', 'Wanda', 'Rocket']

Made me look… I’ve been treating it like .replace(), but am mistaken, it would appear:

queue.remove('Steve')

queue
Out[89]: ['Natasha', 'Wanda', 'Rocket']

This exercise doesn’t require error handling at all, and does not test for it.

I would remove the error handling code, since it might be tossing an error.

1 Like

Noted, thank you. It did pass before I removed it, but I took your advice and removed that code.

Thanks everyone for the quick response.

As an FYI going forward – if the exercise you are working on requires error handling, you will see a note in the directions:

Otherwise, we’re not checking.

2 Likes

Again, noted. Thank you for the head’s up.