Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KevCav - Python 220 Assignments #16

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions students/kevin_cavanaugh/Lesson01/activities/squarer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# squarer.py
class Squarer(object):

@staticmethod
def calc(operand):
return operand*operand

33 changes: 33 additions & 0 deletions students/kevin_cavanaugh/Lesson01/activities/test2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# test2.py
import unittest

from squarer import Squarer


class SquarerTest(unittest.TestCase):

def test_positive_numbers(self):

squares = {
1: 1,
2: 4,
3: 9,
12: 144,
100: 10000,
}

for num, square in squares.items():
self.assertEqual(square, Squarer.calc(num), "Squaring {}".format(num));

def test_negative_numbers(self):

squares = {
-1: 1,
-2: 4,
-3: 9,
-12: 144,
-100: 10000,
}

for num, square in squares.items():
self.assertEqual(square, Squarer.calc(num), "Squaring {}".format(num));
45 changes: 45 additions & 0 deletions students/kevin_cavanaugh/Lesson01/activities/test_squarer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# test.py
from squarer import Squarer


class SquarerTest(object):

@staticmethod
def test_positive_numbers():

squares = {
1: 1,
2: 4,
3: 9,
12: 144,
100: 10000,
}

for num, square in squares.items():
result = Squarer.calc(num)

if result != square:
print("Squared {} and got {} but expected {}".format(num, result, square))

@staticmethod
def test_negative_numbers():

squares = {
-1: 1,
-2: 4,
-3: 9,
-12: 144,
-100: 10000,
}

for num, square in squares.items():
result = Squarer.calc(num)

if result != square:
print("Squared {} and got {} but expected {}".format(num, result, square))


if __name__ == "__main__":
SquarerTest.test_positive_numbers()
SquarerTest.test_negative_numbers()

9 changes: 9 additions & 0 deletions students/kevin_cavanaugh/Lesson01/assignment/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Grading
=======

For assignment 1, you will need to supply your own unit_tests.py 
and integration_test.py files.

The assignment is graded as follows:
1. Run the student unit_tests
2. Run coverage and linting using the regular batch file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
'''
Electric appliances class
'''

from inventory_management.inventory_class import Inventory


class ElectricAppliances(Inventory):
'''
class for electrical appliances
'''

def __init__(self, product_code, description, market_price,
rental_price, brand, voltage):
'''
Creates common instance variables from the parent class
:param product_code:
:param description:
:param market_price:
:param rental_price:
:param brand:
:param voltage:
'''
Inventory.__init__(self, product_code, description,
market_price, rental_price)

self.brand = brand
self.voltage = voltage

def return_as_dictionary(self):
'''
returns electrical appliances dictionary
:return:
'''
output_dict = super().return_as_dictionary()
output_dict['brand'] = self.brand
output_dict['voltage'] = self.voltage

return output_dict
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
'''
Furniture class
'''
from inventory_management.inventory_class import Inventory


class Furniture(Inventory):
'''
class of inventory for furniture
'''

def __init__(self, product_code, description, market_price,
rental_price, material, size):
'''
Creates common instance variables from the parent class
:param product_code:
:param description:
:param market_price:
:param rental_price:
:param material:
:param size:
'''
Inventory.__init__(self, product_code, description,
market_price, rental_price)

self.material = material
self.size = size

def return_as_dictionary(self):
'''
return furniture as a dictionary
:return:
'''
output_dict = super().return_as_dictionary()
output_dict['material'] = self.material
output_dict['size'] = self.size

return output_dict
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
'''
Inventory class
'''


class Inventory:
'''
class for creating inventory objects
'''

def __init__(self, product_code, description,
market_price, rental_price):
'''
construct inventory object
:param product_code:
:param description:
:param market_price:
:param rental_price:
'''
self.product_code = product_code
self.description = description
self.market_price = market_price
self.rental_price = rental_price

def return_as_dictionary(self):
'''
return inventory object as a dictionary
:return:
'''
output_dict = {
'product_code': self.product_code,
'description': self.description,
'market_price': self.market_price,
'rental_price': self.rental_price
}

return output_dict
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
'''
Launches the user interface for the inventory management system
'''
import sys
from inventory_management import market_prices
from inventory_management import inventory_class
from inventory_management import furniture_class
from inventory_management import electric_appliances_class as ea


def main_menu(user_prompt=None):
'''
produces main menu for user interface
:param user_prompt:
:return:
'''
valid_prompts = {"1": add_new_item,
"2": item_info,
"q": exit_program}
options = list(valid_prompts.keys())

while user_prompt not in valid_prompts:
options_str = ("{}" + ", {}" * (len(options)-1)).format(*options)
print(f"Please choose from the following options ({options_str}):")
print("1. Add a new item to the inventory")
print("2. Get item information")
print("q. Quit")
user_prompt = input(">")
return valid_prompts.get(user_prompt)


def get_price(item_code):
'''
prints 'Get price'
:return:
'''

price = FULL_INVENTORY[item_code]['rental_price']

return price


def add_new_item():
'''
add new inventory item
:return:
'''

item_code = input("Enter item code: ")
item_description = input("Enter item description: ")
item_rental_price = input("Enter item rental price: ")

# Get price from the market prices module
item_price = market_prices.get_latest_prices()

is_furniture = input("Is this item a piece of furniture? (Y/N): ")
if is_furniture.lower() == "y":
item_material = input("Enter item material: ")
item_size = input("Enter item size (S,M,L,XL): ")
new_item = furniture_class.Furniture(
item_code, item_description, item_price,
item_rental_price, item_material, item_size)
else:
is_electric_appliance = input(
"Is this item an electric appliance? (Y/N): ")
if is_electric_appliance.lower() == "y":
item_brand = input("Enter item brand: ")
item_voltage = input("Enter item voltage: ")
new_item = ea.ElectricAppliances(
item_code, item_description, item_price,
item_rental_price, item_brand, item_voltage)
else:
new_item = inventory_class.Inventory(
item_code, item_description, item_price, item_rental_price)
FULL_INVENTORY[item_code] = new_item.return_as_dictionary()
print("New inventory item added")
return FULL_INVENTORY[item_code]

def item_info():
'''
prints info for inventory item
:return:
'''
item_code = input("Enter item code: ")
if item_code in FULL_INVENTORY:
print_dict = FULL_INVENTORY[item_code]
output = []
for key, value in print_dict.items():
print("{}:{}".format(key, value))
output.append(print_dict)
else:
print("Item not found in inventory")
output = "Item not found in inventory"

return output


def exit_program():
'''
exits program
:return:
'''
sys.exit()


FULL_INVENTORY = {}

if __name__ == '__main__':

while True:
print(FULL_INVENTORY)
main_menu()()
input("Press Enter to continue...........")
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
"""
Raise an exception to force the user to Mock its output
"""


def get_latest_prices():
"""
get the latest price for an inventory item
"""
return 24
Loading