Question: Why is this unit test failing. Here is my code. def print _ menu ( newCart = None, testing = False, commands = None )
Why is this unit test failing. Here is my code. def printmenunewCartNone, testingFalse, commandsNone:
if newCart is None:
newCart ShoppingCartJohn Doe", "February
customerCart newCart
menu
MENU
a Add item to cart
r Remove item from cart
c Change item quantity
i Output items' descriptions
o Output shopping cart
q Quit
command
commandindex
while command q:
printmenu # Print the menu each time before asking for input
if testing and commands: # During testing, iterate through the given commands
command commandscommandindex
commandindex
else:
try:
command inputChoose an option:
except EOFError:
return # Exit the menu if EOFError is encountered
# Check if the command is valid
while command not in aoiqrc:
if testing and commands:
command commandscommandindex
commandindex
else:
try:
command inputChoose an option:
except EOFError:
return # Exit the menu if EOFError is encountered
# Handle the commands accordingly
if command a:
print
ADD ITEM TO CART"
if not testing:
itemname inputEnter the item name:
itemdescription inputEnter the item description:
itemprice intinputEnter the item price:
itemquantity intinputEnter the item quantity:
else:
itemname, itemdescription, itemprice, itemquantity 'ItemName', 'ItemDesc',
itemtoPurchase ItemToPurchaseitemname, itemprice, itemquantity, itemdescription
customerCart.additemitemtoPurchase
elif command o:
printOUTPUT SHOPPING CART'
customerCart.printtotal
elif command i:
print
OUTPUT ITEMS DESCRIPTIONS'
customerCart.printdescriptions
elif command r:
printREMOVE ITEM FROM CART'
if not testing:
itemName inputEnter name of item to remove:
else:
itemName 'ItemName' # Mock value during testing
customerCart.removeitemitemName
elif command c:
print
CHANGE ITEM QUANTITY'
if not testing:
itemName inputEnter the item name:
qty intinputEnter the new quantity:
else:
itemName, qty 'ItemName', # Mock value during testing
itemToPurchase ItemToPurchaseitemName qty
customerCart.modifyitemitemToPurchase
if namemain:
customername inputEnter customer's name:
currentdate inputEnter today's date:
print
Customer name: s customername
printTodays date: s currentdate
newCart ShoppingCartcustomername, currentdate
printmenunewCart: Unit test
Test printmenu Should output the menu options.
Feedback
printmenu function incorrectly outputted:
MENU
a Add item to cart
r Remove item from cart
c Change item quantity
i Output items' descriptions
o Output shopping cart
q Quit
Choose an option:
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
