def setup_class(self): mi = MobileInventory({ 'iPhone Model A': 50, 'Xiaomi Model B': 2000, 'Nokia Model C': 10, 'Sony Model D': 1 }) self.inventory = mi
def test_creating_inventory_with_negative_value(self): with pytest.raises(ValueError) as error: mi = MobileInventory({ 'iPhone Model X': -45, 'Xiaomi Model Y': 1000, 'Nokia Model Z': 25 }) ex = error.exception assert ex.message == "No. of mobiles must be a positive integer"
def test_creating_inventory_with_numeric_keys(self): with pytest.raises(ValueError) as error: mi = MobileInventory({ 1: 'iPhone Model X', 2: 'Xiaomi Model Y', 3: 'Nokia Model Z' }) ex = error.exception assert ex.message == "Mobile model name must be a string"
def setup_class(cls): cls.inventory = MobileInventory({ 'iPhone Model X': 100, 'Xiaomi Model Y': 1000, 'Nokia Model Z': 25 })
def test_creating_empty_inventory(self): i1 = MobileInventory() assert i1.balance_inventory == {}
def test_creating_inventory_with_list(self): with pytest.raises(TypeError) as error: mi = MobileInventory( ['iPhone Model X', 'Xiaomi Model Y', 'Nokia Model Z']) ex = error.exception assert ex.message == "Input inventory must be a dictionary"
def test_creating_specified_inventory(self): mi = MobileInventory({ 'iPhone Model X': 100, 'Xiaomi Model Y': 1000, 'Nokia Model Z': 25 })