Hands On Python Qualis Pytest
Hands On Python Qualis Pytest
class InsufficientException(Exception):
pass
class MobileInventory:
if type(inventory) != dict:
self.balanced_inventory = inventory
for i in inventory.keys():
if type(i) != str:
for i in inventory.values():
self.balanced_inventory = inventory
if type(new_stock) != dict:
for i in new_stock.keys():
if type(i) != str:
for i in new_stock.values():
This study source was downloaded by 100000832806195 from CourseHero.com on 01-10-2022 00:37:01 GMT -06:00
https://www.coursehero.com/file/72269612/HANDS-ON-PYTHON-QUALIS-PYTESTdocx/
raise ValueError("No. of mobiles must be a positive integer")
self.balanced_inventory.update(new_stock)
if type(requested_stock) != dict:
mobileName = []
mobileQuantity = []
for i in requested_stock.keys():
if type(i) != str:
for i in requested_stock.values():
for i in requested_stock.keys():
if i not in self.balanced_inventory.keys():
else:
self.balanced_inventory[i] = (
self.balanced_inventory[i] - requested_stock[i]
PART 2
import pytest
This study source was downloaded by 100000832806195 from CourseHero.com on 01-10-2022 00:37:01 GMT -06:00
https://www.coursehero.com/file/72269612/HANDS-ON-PYTHON-QUALIS-PYTESTdocx/
class TestingInventoryCreation:
def test_creating_empty_inventory(self):
c1 = MobileInventory({})
assert c1.balanced_inventory == {}
def test_creating_specified_inventory(self):
c2 = MobileInventory(
{"iPhone Model X": 100, "Xiaomi Model Y": 1000, "Nokia Model Z": 25}
assert c2.balanced_inventory == {
def test_creating_inventory_with_list(self):
def test_creating_inventory_with_numeric_keys(self):
c4 = MobileInventory(
{1: "iPhone Model X", 2: "Xiaomi Model Y", 3: "Nokia Model Z"}
def test_creating_inventory_with_nonnumeric_values(self):
c5 = MobileInventory(
This study source was downloaded by 100000832806195 from CourseHero.com on 01-10-2022 00:37:01 GMT -06:00
https://www.coursehero.com/file/72269612/HANDS-ON-PYTHON-QUALIS-PYTESTdocx/
{
def test_creating_inventory_with_negative_value(self):
c6 = MobileInventory(
{"iPhone Model X": -45, "Xiaomi Model Y": 200, "Nokia Model Z": 25}
PART 3
class TestInventoryAddStock():
def setup_class(cls):
cls.inventory = MobileInventory({'iPhone Model X': 100, 'Xiaomi Model Y': 1000, 'Nokia Model
Z':25})
def test_add_new_stock_as_dict(self):
with pytest.raises(TypeError) :
def test_add_new_stock_as_list(self):
This study source was downloaded by 100000832806195 from CourseHero.com on 01-10-2022 00:37:01 GMT -06:00
https://www.coursehero.com/file/72269612/HANDS-ON-PYTHON-QUALIS-PYTESTdocx/
def test_add_new_stock_with_numeric_keys(self):
def test_add_new_stock_with_nonnumeric_values(self):
def test_add_new_stock_with_float_values(self):
class TestInventorySellStock:
inventory = None
@classmethod
def setup_class(cls):
cls.inventory = MobileInventory(
This study source was downloaded by 100000832806195 from CourseHero.com on 01-10-2022 00:37:01 GMT -06:00
https://www.coursehero.com/file/72269612/HANDS-ON-PYTHON-QUALIS-PYTESTdocx/
def test_sell_stock_as_dict(self):
self.inventory.sell_stock(
{"iPhone Model A": 2, "Xiaomi Model B": 20, "Sony Model D": 1}
def test_sell_stock_as_list(self):
with pytest.raises(TypeError):
MobileInventory.sell_stock(
self, ["iPhone Model A", "Xiaomi Model B", "Nokia Model C"]
def test_sell_stock_with_numeric_keys(self):
with pytest.raises(ValueError):
MobileInventory.sell_stock(
self, {1: "iPhone Model A", 2: "Xiaomi Model B", 3: "Nokia Model C"}
def test_sell_stock_with_nonnumeric_values(self):
with pytest.raises(ValueError):
MobileInventory.sell_stock(
self,
{"iPhone Model A": "5", "Xiaomi Model B": "3", "Nokia Model C": "4"},
def test_sell_stock_of_nonexisting_model(self):
def test_sell_stock_of_insufficient_stock(self):
This study source was downloaded by 100000832806195 from CourseHero.com on 01-10-2022 00:37:01 GMT -06:00
https://www.coursehero.com/file/72269612/HANDS-ON-PYTHON-QUALIS-PYTESTdocx/
with pytest.raises(InsufficientException, match="Insufficient Stock"):
self.inventory.sell_stock(
{"iPhone Model A": 2, "Xiaomi Model B": 5, "Nokia Model C": 15}
This study source was downloaded by 100000832806195 from CourseHero.com on 01-10-2022 00:37:01 GMT -06:00
https://www.coursehero.com/file/72269612/HANDS-ON-PYTHON-QUALIS-PYTESTdocx/
Powered by TCPDF (www.tcpdf.org)