Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This implementation looks great; now we need some tests to go with it (otherwise we have no guarantee that the code will keep working!)
Batavia tests take the form of samples of Python code that will be executed in both CPython and Batavia; the test case then compares the output of both runs to check that they're the same.
If you look in the datatype tests, test methods with calls to assertCodeExecution
are what you're looking for. Add some tests like those to test frozenSet behavior, and this PR should be good to go!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good; one small tweak needed on the test cases, and we should be good to merge!
tests/datatypes/test_frozenset.py
Outdated
y = frozetset([3,4,7,9]) | ||
z = 5 | ||
print(x.union(y)) | ||
print(x.union(z)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a good test, and it probably passes, but it's not the right way to test it in Batavia.
Batavia tests are based on comparing output of two program runs; and, to do that, it's necessary for both programs to terminate successfully, not raise an error.
If you're testing behavior that you know will (and should) raise an error, your test code should catch the exception and print a "raised an error" message; that way, the comparison has something to match up.
I made some changes but there is an important issue that could be addressed in order to make these tests pass. When you do the following in CPython: However, when you do the same in Batavia, the program will not return the set in increasing order. This makes the union function return a frozen set that is not increasing order, which in turn makes the tests fail. In order to make the union function return exactly the same as CPython, changes unrelated to the union method would have to be implemented. |
CPython isn't quite as predictable in its ordering. These tests could be made to pass by changing print(frozenset... to print(sorted(frozenset... if the sorted() builtin was implemented. Barring that, it looks like changing the format to something that tests properties of the output set would cover this. Like:
|
Hi there! It looks like this PR might be dead, so we're closing it for now. Feel free to re-open it if you'd like to continue, or think about directing your efforts to https://github.com/beeware/briefcase or https://github.com/beeware/toga. Both of these have more active development right now. 😄 |
These are the union and intersection methods for frozen set.