exercism / python

Exercism exercises in Python.
https://exercism.org/tracks/python
MIT License
1.94k stars 1.29k forks source link

[Cater Waiter] test for separate_appetizers function accepts a set in return statement #3190

Closed list4c closed 1 year ago

list4c commented 2 years ago

I was doing the task no. 6 'Pull out Appetizers for Passing on Trays' and found out that my result passes tests even though it's a set and not a list.

This is because the test uses the sorted() function which returns an object with list type. I think this is a bug, because the requirements said I should return a list.
My idea of fixing the test is to use the method sort() instead of sorted().

self.assertEqual((separate_appetizers(item[0], item[1]).sort()), (result.sort()), msg=error_message)

In this case my solution does not pass and I get the following error:

AttributeError: 'set' object has no attribute 'sort'

Which may probably be a bit confusing for someone checking test output, but maybe there is a way to catch this error and throw a custom message.

github-actions[bot] commented 2 years ago

🤖   🤖

Hi! 👋🏽 👋 Welcome to the Exercism Python Repo!

Thank you for opening an issue! 🐍  🌈 ✨


​          ◦ If you'd also like to make a PR to fix the issue, please have a quick look at the Pull Requests doc.
             We  💙  PRs that follow our Exercism & Track contributing guidelines!


💛  💙  While you are here... If you decide to help out with other open issues, you have our gratitude 🙌 🙌🏽.
Anything tagged with [help wanted] and without [Claimed] is up for grabs.
Comment on the issue and we will reserve it for you. 🌈 ✨

BethanyG commented 1 year ago

@list4c - That is an excellent catch! Thank you for submitting this issue - and apologies for the extreme delay in getting back to you. I've submitted a PR to fix this. I don't like having two assertions in the same test, but I think it might be cleaner to do that instead of doing a whole separate test just to check the return type.

I considered using sort(), but its harder to then trap the error and surface it as a test failure.

Please let me know if you have questions or issues. Thanks again for reporting this.

list4c commented 1 year ago

Hi, cool! Thanks, looks meaningful and will nicely warn users that they return an incorrect data structure.