Sphinx Class_Astry & Rong#7
Conversation
yangashley
left a comment
There was a problem hiding this comment.
Nice job on swap-meet, Astry and Rong!
I can see from the commit history that you made frequent commits, which is great!
Let me know if you have any questions about my comments.
| @@ -1,2 +1,10 @@ | |||
| class Clothing: | |||
| pass No newline at end of file | |||
| from swap_meet.item import Item | |||
There was a problem hiding this comment.
Nice work importing Item since we're using by name as the parent class of Clothing 👍
| def __init__(self, id=None, fabric="Unknown", condition=0): | ||
| super().__init__(id=id, condition=condition) |
There was a problem hiding this comment.
Nice work on here!
On line 4 you correctly set the default value for fabric to "Unknown"
On line 5 you properly call the initializer of the parent, and pass along the values the child wants to use.
|
|
||
| class Item: | ||
| pass No newline at end of file | ||
| def __init__(self,id=None, condition=0, age=0): |
There was a problem hiding this comment.
| def __init__(self,id=None, condition=0, age=0): | |
| def __init__(self, id=None, condition=0, age=0): |
Nit: You're missing a whitespace after the first comma. Be mindful to use/exclude whitespaces where necessary. It is easy to overlook, but having inconsistent use of whitespaces leads to a messy codebase.
Here's the section on whitespaces in the PEP8 styleguide.
| self.fabric = fabric | ||
|
|
||
| def __str__(self): | ||
| return f"An object of type Clothing with id {self.id}. It is made from {self.fabric} fabric." |
There was a problem hiding this comment.
This method looks similar to the method you wrote in the Item parent class.
In that class __str__ returns f"An object of type Item with id {self.id}."
What if the __str__ method for the Clothing class could inherit this behavior from the parent class and then append the sentence with the second part of the fabric message "It is made from {self.fabric} fabric." ?
Currently, it's not possible because Item's __str__ method hardcodes the classtype "Item" in the string it returns. However, you could refactor the method to make it more dynamic so that it will print any class's name.
After Item's __str__ method is refactored, then Clothing's method could override it like this:
def __str__(self):
type_str = super().__str__()
fabric_str = f"It is made from {self.fabric} fabric."
return " ".join([type_str, fabric_str])| self.width = width | ||
| self.length = length | ||
|
|
||
| def __str__(self): |
There was a problem hiding this comment.
See comment from clothing.py about refactoring this method so it overrides the parent class's __str__ method.
| def get_newest_item(self): | ||
| newest_item = self.inventory[0] | ||
|
|
||
| for item in self.inventory: | ||
| if item.age < newest_item.age: | ||
| newest_item = item | ||
|
|
||
| return newest_item | ||
|
|
||
| def swap_by_newest(self, other_vendor): | ||
| my_newest_item = self.get_newest_item() | ||
| their_newest_item = other_vendor.get_newest_item() | ||
|
|
||
| return self.swap_items(other_vendor, my_newest_item, their_newest_item) |
| assert len(fatimah.inventory) == 3 | ||
| assert item_b in fatimah.inventory | ||
| assert item_a not in fatimah.inventory | ||
| assert item_c in fatimah.inventory | ||
| assert item_d in fatimah.inventory | ||
| assert len(jolie.inventory) == 2 | ||
| assert item_d not in jolie.inventory | ||
| assert item_e in jolie.inventory | ||
| assert item_a in jolie.inventory | ||
| assert result No newline at end of file |
There was a problem hiding this comment.
LGTM! Gad you got some additional practice with this optional enhancement!
| # ********************************************************************* | ||
| # ****** Complete Assert Portion of this test ********** | ||
| # ********************************************************************* | ||
| assert result == False |
There was a problem hiding this comment.
Since the general intention of this method is to modify the inventory, we want to check this condition as well to make sure that the items that started in the inventory are still there. Adding these assertions would make the test more robust.
assert len(vendor.inventory) == 3
assert "a" in vendor.inventory
assert "b" in vendor.inventory
assert "c" in vendor.inventory| # ********************************************************************* | ||
| assert len(jolie.inventory) == 0 | ||
| assert len(fatimah.inventory) == 3 | ||
| assert not result |
There was a problem hiding this comment.
More than be falsy, swap_items is intended to return an actual boolean. So while we typically write something like
assert not resultin regular python, here we might prefer the more explicit check of
assert result == FalseYou could make this test more robust by verifying that the items in the unchanged inventory are actually the items we started with (and not some other 3 items)
assert item_a in fatimah.inventory
assert item_b in fatimah.inventory
assert item_c in fatimah.inventory| assert item_f not in jesse.inventory | ||
| assert item_c not in tai.inventory |
There was a problem hiding this comment.
We don't need to include the not in checks since the other checks already rule them out.
No description provided.