Could you help me to fix the problems? The test code crashes when it runs throught removeOneOfItem
-untitled , Baglist.py) Aurittest BogTest.testRemoveOne ▼ a Project ▼しuntitled ~/untitled class Bag def _init_(self): selt . storage list() BagList.py 呻test-Bag.py 1111 External Libraries make bag as an iterator def iter(selt): for element in self.storage: yield elerent adding one element into bag def insertiself, elenent): 10 self.storage.append(elenent) 12 13 14 15 get countOf a type of elements in the bag def countofiselt, elenent): countNum = 0 for i in range en(self.storage): 17 18 19 20 21 if self.storage [1] element: countNun 1 return countNun 23 # remove one of the item return True if element got removed; # return False if element not found Itentself, elenent): def 26 27 28 29 30 31 32 for 1 in range(Len(self.storage)): assert isinstance(elenent if self.sto rageli! = element; self.storage [1] self.storage.pop( return True self. Storage [-1] return False 34 35 36 remove all of the item def removeAllotIten(self, elenent): Run: Unittests in test Bag Unittest BagTest.testRemoveOne 旮- 1 test failed-0ms ▼ Test Results /Library/Frameworks/Python. Tramework/Versions/3.6/bin/python3.6 “/Applications/PyCharm CE.app/Contents/helpers/pycharm/utrunner-py” Users/nike/untitled/te o test-Bag.BagTest testRemoveOne oms Testing started at 14:2« ..- oms Error ▼ Traceback (most recent call last): File” , line 70, in testRemoveOne b. renoveOneorItem(3) File “Users/mike/untitLed/BagList.py” line 28, in removeDneofItem assert isinstance(element) TypeError: isinstance expected 2 argunents, got 1 Process finished with exit code 0 Parameter class or type or tuple’ unfilled 28:39 LF: UTF-8; Q
Expert Answer
In your script, line 28, in removeOfitem(self, element), you are calling isinstance() function.
isinstance() function takes two arguments, and here is the syntax, isinstance(object, class) where object is the object name and class is the class of the object.
isinstance(object, class) returns true if the object is the instance of the class.
In your script, the error is, you’re supplying only one argument for isinstance(element). You also need to pass the class of the element, and then the program will run.