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 print_menu(newCart=None, testing=False, commands=None):
if newCart is None:
newCart = ShoppingCart("John Doe", "February 1,2016")
customer_Cart = 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 =''
command_index =0
while command !='q':
print(menu) # Print the menu each time before asking for input
if testing and commands: # During testing, iterate through the given commands
command = commands[command_index]
command_index +=1
else:
try:
command = input('Choose an option:
')
except EOFError:
return # Exit the menu if EOFError is encountered
# Check if the command is valid
while command not in ['a','o','i','q','r','c']:
if testing and commands:
command = commands[command_index]
command_index +=1
else:
try:
command = input('Choose 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:
item_name = input('Enter the item name:
')
item_description = input('Enter the item description:
')
item_price = int(input('Enter the item price:
'))
item_quantity = int(input('Enter the item quantity:
'))
else:
item_name, item_description, item_price, item_quantity = 'ItemName', 'ItemDesc', 10,1
itemtoPurchase = ItemToPurchase(item_name, item_price, item_quantity, item_description)
customer_Cart.add_item(itemtoPurchase)
elif command =='o':
print('OUTPUT SHOPPING CART')
customer_Cart.print_total()
elif command =='i':
print('
OUTPUT ITEMS\' DESCRIPTIONS')
customer_Cart.print_descriptions()
elif command =='r':
print('REMOVE ITEM FROM CART')
if not testing:
itemName = input('Enter name of item to remove:
')
else:
itemName = 'ItemName' # Mock value during testing
customer_Cart.remove_item(itemName)
elif command =='c':
print('
CHANGE ITEM QUANTITY')
if not testing:
itemName = input('Enter the item name:
')
qty = int(input('Enter the new quantity:
'))
else:
itemName, qty = 'ItemName', 2 # Mock value during testing
itemToPurchase = ItemToPurchase(itemName,0, qty)
customer_Cart.modify_item(itemToPurchase)
if __name__=="__main__":
customer_name = input("Enter customer's name:
")
current_date = input("Enter today's date:
")
print("
Customer name: %s"% customer_name)
print("Today's date: %s"% current_date)
newCart = ShoppingCart(customer_name, current_date)
print_menu(newCart)6: Unit test
Test print_menu(). Should output the menu options.
Feedback
print_menu() 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:
Why is this unit test failing. Here is my code.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!