Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

A folder named 'Project' having two subfolders 'proj' and 'test' inside it. The 'proj' folder contains an empty ' init .py' file and also an

A folder named 'Project' having two subfolders 'proj' and 'test' inside it. The 'proj' folder contains an empty 'init.py' file and also an empty 'init.py' inside the 'test' folder.In inventory.py' file,

  • Define a child class'InsufficientException'derived from'Exception'as follows:py
  • class InsufficientException(Exception):
  • pass
  • Define a class'MobileInventory'with the following specifications:
  • Define the class method '__init__', which initializes an instance of'MobileInventory'and accepts an input through the argument'inventory', and assigns the value to the attribute'balance_inventory'.
  • By default, the'inventory'argument's value is 'None'. If no input value is passed to the argument'inventory', the attribute'balance_inventory'is set to an empty dictionary-{}.
  • The input value passed to the argument'inventory'must be a dictionary. If the input is not a dictionary, raise a TypeError Exception with the message "Input inventory must be a dictionary".
  • Keys of the dictionary must be a string, representing mobile model names. If the given key is not a string, raise ValueError with the message "Mobile model name must be a string".
  • Values of the dictionary must be positive integers, representing the number of available handsets corresponding to various mobile models. If the given value is not a positive integer, raise ValueError with the message "No. of mobiles must be a positive integer".
  • A sample input dictionary can be {'iPhone Model X':100, 'Xiaomi Model Y': 1000, 'Nokia Model Z':25}.
  • Define the class method'add_stock', which adds new stock of mobiles to existing inventory. It accepts an input through the argumentnew_stock, and updates the 'balance_inventory'. based on the inputnew_stock.
  • The input value passed to'new_stock'argument must be a dictionary. If the input is not a dictionary, raise a TypeError Exception with the message "Input stock must be a dictionary".
  • Keys of the dictionary must be a string, representing mobile model names. If the given key is not a string, raise a ValueError with the message "Mobile model name must be a string".
  • Values of the dictionary must be positive integers, representing the number of available handsets corresponding to various mobile models. If the given value is not a positive integer, raise a ValueError with the message "No. of mobiles must be a positive integer".
  • Define the class method'sell_stock', which sells the request mobile handsets to customers. It accepts an input through the argumentrequested_stock, and updates the 'balance_inventory' attribute based on the inputrequested_stock.
  • The input value passed to the'requested_stock'argument must be a dictionary. If the input is not a dictionary, raise a TypeError Exception with the message "Requested stock must be a dictionary".
  • Keys of the dictionary must be a string, representing mobile model names. If the given key is not a string, raise ValueError with the message "Mobile model name must be a string".
  • Values of the dictionary must be positive integers, representing the number of available handsets corresponding to various mobile models. If the given value is not a positive integer, raise a ValueError with the message "No. of mobiles must be a positive integer".
  • Before selling, check if the requested mobile handset model is part of the existing inventory. If not, raise an InsufficientException with the error message "No Stock. New Model Request".
  • If the requested number of mobile handsets are not available in the inventory, raise an InsufficientException with the error message "Insufficient Stock".

  • Ensure you are in the 'Project' folder.
  • Open the 'test/test_inventory.py' file.
  • ImportMobileInventoryclass andInsufficientExceptionfrom theinventorymodule using the expressionfrom proj.inventory import MobileInventory, InsufficientException.
  • Importpytestusing the expressionimport pytest.
  • Define a pytest test class'TestingInventoryCreation'which tests the behavior of the'__init__'method with the following tests:
  • Define a pytest test method'test_creating_empty_inventory', which creates an empty inventory and checks if its 'balance_inventory' is an empty dict.
  • Define a pytest test method'test_creating_specified_inventory', which creates an inventory instance with input {'iPhone Model X':100, 'Xiaomi Model Y': 1000, 'Nokia Model Z':25}.
  • Define a pytest test method'test_creating_inventory_with_list', which checks if the'__init__'method raises a TypeError with the message "Input inventory must be a dictionary" when a list "['iPhone Model X', 'Xiaomi Model Y', 'Nokia Model Z']" is passed as input.
  • Define a pytest test method'test_creating_inventory_with_numeric_keys', which checks if the'__init__'method raises a ValueError with the message "Mobile model name must be a string", when the dict {1:'iPhone Model X', 2:'Xiaomi Model Y', 3:'Nokia Model Z'} is passed as input.
  • Define a pytest test method'test_creating_inventory_with_nonnumeric_values', which checks if the'__init__'method raises a ValueError with the message "No. of mobiles must be a positive integer" when the dict {'iPhone Model X':'100', 'Xiaomi Model Y': '1000', 'Nokia Model Z':'25'} is passed as input.
  • Define a pytest test method'test_creating_inventory_with_negative_value', which checks if the'__init__'method raises a ValueError with the message "No. of mobiles must be a positive integer" when the dict {'iPhone Model X':-45, 'Xiaomi Model Y': 200, 'Nokia Model Z':25} is passed as input.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Financial management theory and practice

Authors: Eugene F. Brigham and Michael C. Ehrhardt

12th Edition

978-0030243998, 30243998, 324422695, 978-0324422696

Students also viewed these Programming questions

Question

please dont use chat gpt 5 3 1 . .

Answered: 1 week ago