From f36d350227dbffe7559fc72a7617d9033075fc63 Mon Sep 17 00:00:00 2001 From: Andy Miles Date: Fri, 29 Mar 2019 11:37:20 -0700 Subject: [PATCH 01/11] initial setup --- README.md | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index ea8e28e..5b8ff74 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,3 @@ -# 220-Advanced-Template -## Not for class use - Fork me! +# Python 220: online cohort April 2019 +## Class repo for grading -This is the master repo from which an instructor will use a fork to create their class assignment repo. - -PLEASE do not use this for your students' assignments. From ac8d72cc32ca0e39acd8053ba80eb0636a5ce3b5 Mon Sep 17 00:00:00 2001 From: Andy Miles Date: Fri, 29 Mar 2019 12:00:17 -0700 Subject: [PATCH 02/11] added git links --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index 5b8ff74..bea97d6 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,7 @@ # Python 220: online cohort April 2019 ## Class repo for grading +Links for setting up git for this class: + +- https://uwpce-pythoncert.github.io/PythonCertDevel220/modules/lesson00/git_setup.html +- https://uwpce-pythoncert.github.io/PythonCertDevel220/modules/lesson00/git_workflow.html From 8c2dab830cb1c887d11fe58bc34a5c005d091054 Mon Sep 17 00:00:00 2001 From: awhitty1 <38850466+awhitty1@users.noreply.github.com> Date: Mon, 1 Apr 2019 18:35:09 -0700 Subject: [PATCH 03/11] Create test.txt --- students/AlexW/test.txt | 1 + 1 file changed, 1 insertion(+) create mode 100644 students/AlexW/test.txt diff --git a/students/AlexW/test.txt b/students/AlexW/test.txt new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/students/AlexW/test.txt @@ -0,0 +1 @@ + From 8c00d73a517470711cb7ecb991ad40cca122372f Mon Sep 17 00:00:00 2001 From: UncleanlyCleric Date: Mon, 1 Apr 2019 18:40:23 -0700 Subject: [PATCH 04/11] Setting up userdir --- students/jesse_miller/README.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 students/jesse_miller/README.md diff --git a/students/jesse_miller/README.md b/students/jesse_miller/README.md new file mode 100644 index 0000000..7a40bbb --- /dev/null +++ b/students/jesse_miller/README.md @@ -0,0 +1 @@ +New dir From 51d655c0b23a3d591dbca1a3902b0286e0de1134 Mon Sep 17 00:00:00 2001 From: UncleanlyCleric Date: Mon, 1 Apr 2019 21:32:51 -0700 Subject: [PATCH 05/11] Calculator lab --- .../jesse_miller/lesson01/calculator/adder.py | 15 +++++ .../lesson01/calculator/calculator.py | 60 +++++++++++++++++++ .../lesson01/calculator/divider.py | 15 +++++ .../lesson01/calculator/multiplier.py | 15 +++++ .../lesson01/calculator/squarer.py | 14 +++++ .../lesson01/calculator/subtractor.py | 15 +++++ 6 files changed, 134 insertions(+) create mode 100644 students/jesse_miller/lesson01/calculator/adder.py create mode 100644 students/jesse_miller/lesson01/calculator/calculator.py create mode 100644 students/jesse_miller/lesson01/calculator/divider.py create mode 100644 students/jesse_miller/lesson01/calculator/multiplier.py create mode 100644 students/jesse_miller/lesson01/calculator/squarer.py create mode 100644 students/jesse_miller/lesson01/calculator/subtractor.py diff --git a/students/jesse_miller/lesson01/calculator/adder.py b/students/jesse_miller/lesson01/calculator/adder.py new file mode 100644 index 0000000..011a1ed --- /dev/null +++ b/students/jesse_miller/lesson01/calculator/adder.py @@ -0,0 +1,15 @@ +#!/usr/bin/env python3 +''' +Addition module for calculator +''' +class Adder(): + ''' + Addition class for a more complex calculator + ''' + + @staticmethod + def calc(operand_1, operand_2): + ''' + This does the heavy lifting for adding + ''' + return operand_1 + operand_2 diff --git a/students/jesse_miller/lesson01/calculator/calculator.py b/students/jesse_miller/lesson01/calculator/calculator.py new file mode 100644 index 0000000..52454d0 --- /dev/null +++ b/students/jesse_miller/lesson01/calculator/calculator.py @@ -0,0 +1,60 @@ +#!/usr/bin/env python3 +''' +Our calculator +''' +class Calculator(): + ''' + Class base for the calculator + ''' + def __init__(self, adder, subtractor, multiplier, divider): + self.adder = adder + self.subtractor = subtractor + self.multiplier = multiplier + self.divider = divider + + self.stack = [] + + + def enter_number(self, number): + ''' + What it says on the tin. Enter a number. + ''' + self.stack.insert(0, number) + + + def _do_calc(self, operator): + ''' + Shortcut to operations on numbers. Keeps from having to repeat whole + functions. + ''' + result = operator.calc(self.stack[0], self.stack[1]) + self.stack = [result] + return result + + + def add(self): + ''' + Addition method + ''' + return self._do_calc(self.adder) + + + def subtract(self): + ''' + Subtraction method + ''' + return self._do_calc(self.subtractor) + + + def multiply(self): + ''' + Multiplication method + ''' + return self._do_calc(self.multiplier) + + + def divide(self): + ''' + Division method + ''' + return self._do_calc(self.divider) diff --git a/students/jesse_miller/lesson01/calculator/divider.py b/students/jesse_miller/lesson01/calculator/divider.py new file mode 100644 index 0000000..519590d --- /dev/null +++ b/students/jesse_miller/lesson01/calculator/divider.py @@ -0,0 +1,15 @@ +#!/usr/bin/env python3 +''' +Division module for calculator +''' +class Divider(): + ''' + Division class for a more complex calculator + ''' + + @staticmethod + def calc(operand_1, operand_2): + ''' + This does the heavy lifting for division + ''' + return operand_1 / operand_2 diff --git a/students/jesse_miller/lesson01/calculator/multiplier.py b/students/jesse_miller/lesson01/calculator/multiplier.py new file mode 100644 index 0000000..d5adf85 --- /dev/null +++ b/students/jesse_miller/lesson01/calculator/multiplier.py @@ -0,0 +1,15 @@ +#!/usr/bin/env python3 +''' +Multiplication module for calculator +''' +class Multiplier(): + ''' + Multiplying class for a more complex calculator + ''' + + @staticmethod + def calc(operand_1, operand_2): + ''' + This does the heavy lifting for multiplying + ''' + return operand_1 * operand_2 diff --git a/students/jesse_miller/lesson01/calculator/squarer.py b/students/jesse_miller/lesson01/calculator/squarer.py new file mode 100644 index 0000000..60512f8 --- /dev/null +++ b/students/jesse_miller/lesson01/calculator/squarer.py @@ -0,0 +1,14 @@ +#!/usr/bin/env python3 +class Squarer(object): + ''' + A simple squaring function + ''' + + @staticmethod + def calc(operand): + ''' + calculating the square + ''' + #return operand**2 # OLD + #return operand**operand # BAD + return operand*operand # This should work diff --git a/students/jesse_miller/lesson01/calculator/subtractor.py b/students/jesse_miller/lesson01/calculator/subtractor.py new file mode 100644 index 0000000..77efcbe --- /dev/null +++ b/students/jesse_miller/lesson01/calculator/subtractor.py @@ -0,0 +1,15 @@ +#!/usr/bin/env python3 +''' +Subtraction module for calculator +''' +class Subtractor(): + ''' + Addition class for a more complex calculator + ''' + + @staticmethod + def calc(operand_1, operand_2): + ''' + This does the heavy lifting for subtracting + ''' + return operand_1 - operand_2 From cf27b4561aba3ef78fa394fb37eb1ad9d96880a6 Mon Sep 17 00:00:00 2001 From: UncleanlyCleric Date: Mon, 1 Apr 2019 23:44:14 -0700 Subject: [PATCH 06/11] Learning to read directions --- .../jesse_miller/lesson01/activity/README.md | 32 +++ .../lesson01/activity/calculator/adder.py | 18 ++ .../activity/calculator/calculator.py | 62 +++++ .../lesson01/activity/calculator/divider.py | 16 ++ .../activity/calculator/exceptions.py | 3 + .../activity/calculator/multiplier.py | 16 ++ .../lesson01/activity/calculator/squarer.py | 14 ++ .../activity/calculator/subtracter.py | 16 ++ .../lesson01/activity/calculator/test.py | 109 ++++++++ .../lesson01/activity/squarer/squarer.py | 17 ++ .../lesson01/activity/squarer/test.py | 41 +++ .../lesson01/activity/squarer/test2.py | 32 +++ .../lesson01/activity/test_integration.py | 35 +++ .../lesson01/activity/test_unit.py | 65 +++++ .../lesson01/assignment/README.md | 9 + .../electricAppliancesClass.py | 22 ++ .../inventory_management/furnitureClass.py | 21 ++ .../inventory_management/inventoryClass.py | 17 ++ .../assignment/inventory_management/main.py | 69 +++++ .../inventory_management/market_prices.py | 3 + .../jesse_miller/lesson01/assignment/pylintrc | 236 ++++++++++++++++++ .../lesson01/assignment/tests/README.md | 1 + 22 files changed, 854 insertions(+) create mode 100755 students/jesse_miller/lesson01/activity/README.md create mode 100644 students/jesse_miller/lesson01/activity/calculator/adder.py create mode 100644 students/jesse_miller/lesson01/activity/calculator/calculator.py create mode 100644 students/jesse_miller/lesson01/activity/calculator/divider.py create mode 100644 students/jesse_miller/lesson01/activity/calculator/exceptions.py create mode 100644 students/jesse_miller/lesson01/activity/calculator/multiplier.py create mode 100644 students/jesse_miller/lesson01/activity/calculator/squarer.py create mode 100644 students/jesse_miller/lesson01/activity/calculator/subtracter.py create mode 100644 students/jesse_miller/lesson01/activity/calculator/test.py create mode 100644 students/jesse_miller/lesson01/activity/squarer/squarer.py create mode 100644 students/jesse_miller/lesson01/activity/squarer/test.py create mode 100644 students/jesse_miller/lesson01/activity/squarer/test2.py create mode 100755 students/jesse_miller/lesson01/activity/test_integration.py create mode 100755 students/jesse_miller/lesson01/activity/test_unit.py create mode 100755 students/jesse_miller/lesson01/assignment/README.md create mode 100755 students/jesse_miller/lesson01/assignment/inventory_management/electricAppliancesClass.py create mode 100755 students/jesse_miller/lesson01/assignment/inventory_management/furnitureClass.py create mode 100755 students/jesse_miller/lesson01/assignment/inventory_management/inventoryClass.py create mode 100755 students/jesse_miller/lesson01/assignment/inventory_management/main.py create mode 100755 students/jesse_miller/lesson01/assignment/inventory_management/market_prices.py create mode 100644 students/jesse_miller/lesson01/assignment/pylintrc create mode 100644 students/jesse_miller/lesson01/assignment/tests/README.md diff --git a/students/jesse_miller/lesson01/activity/README.md b/students/jesse_miller/lesson01/activity/README.md new file mode 100755 index 0000000..af9b79d --- /dev/null +++ b/students/jesse_miller/lesson01/activity/README.md @@ -0,0 +1,32 @@ +# Calculator + +## Instructions + +Your assignment is to complete testing and linting on the calculator from the lesson videos. + +There's one new addition since the videos: I've separated the unit tests and the integration tests into two separate test files. + +## Your Goals + +1. `python -m unittest integration-test` should have no failures. Don't edit integration-test.py, edit your code to make it pass. +2. Add unit tests to unit-test.py such that `coverage run --source=calculator -m unittest unit-test; coverage report` shows 100% coverage. +3. All of the tests in unit-test.py should pass. +4. Satisfy the linter such that `pylint calculator` gives no errors and `flake8 calculator` gives no errors. See (PEP257)[https://www.python.org/dev/peps/pep-0257/] if you'd like more information about docstrings. There are quite a few docstrings to add, but for this exercise you don't need to get too creative: """ this method adds two numbers """ is sufficient. + +## Bonus goal +One of our specs for calculator says the following: + +``` +The add, subtract, multiply, and divide methods shall both: +Return the result of the operation +Enter the result of the operation back into the calculator +This makes it possible to perform the following sequences of operations: + calculator.enter_number(2) + calculator.enter_number(3) + calculator.add() # Returns 5, and now 5 is now 'in the calculator' + calculator.enter_number(1) + calculator.subtract() # Returns 4 because 5 - 1 = 4 +``` + +This feature is tested by our integration test, but it is not tested in our unit tests. Because this sequencing of operations is a defined feature of calculator, it would definitely be appropriate to test in the unit-test.CalculatorTests. Your bonus goal is to use *MagicMock* to test this method sequencing feature in isolation. Ie: without relying on the correctness of any particular operator we use to initialize our calculator. + diff --git a/students/jesse_miller/lesson01/activity/calculator/adder.py b/students/jesse_miller/lesson01/activity/calculator/adder.py new file mode 100644 index 0000000..874a057 --- /dev/null +++ b/students/jesse_miller/lesson01/activity/calculator/adder.py @@ -0,0 +1,18 @@ +#!/usr/bin/env python3 +#pylint: disable=R0903 +''' +Addition module for calculator +''' + + +class Adder(): + ''' + Addition class for a more complex calculator + ''' + + @staticmethod + def calc(operand_1, operand_2): + ''' + This does the heavy lifting for adding + ''' + return operand_1 + operand_2 diff --git a/students/jesse_miller/lesson01/activity/calculator/calculator.py b/students/jesse_miller/lesson01/activity/calculator/calculator.py new file mode 100644 index 0000000..cdfecff --- /dev/null +++ b/students/jesse_miller/lesson01/activity/calculator/calculator.py @@ -0,0 +1,62 @@ +#!/usr/bin/env python3 +''' +Our calculator +''' +from exceptions import InsufficientOperands + + +class Calculator(): + ''' + Class base for the calculator + ''' + + def __init__(self, adder, subtracter, multiplier, divider): + self.adder = adder + self.subtracter = subtracter + self.multiplier = multiplier + self.divider = divider + + self.stack = [] + + def enter_number(self, number): + ''' + What it says on the tin. Enter a number. + ''' + self.stack.insert(0, number) + + def _do_calc(self, operator): + ''' + Shortcut to operations on numbers. Keeps from having to repeat whole + functions. + ''' + try: + result = operator.calc(self.stack[1], self.stack[0]) + except IndexError: + raise InsufficientOperands + + self.stack = [result] + return result + + def add(self): + ''' + Addition method + ''' + return self._do_calc(self.adder) + + def subtract(self): + ''' + Subtraction method + ''' + return self._do_calc(self.subtracter) + + def multiply(self): + ''' + Multiplication method + ''' + return self._do_calc(self.multiplier) + + def divide(self): + ''' + Division method + ''' + return self._do_calc(self.divider) diff --git a/students/jesse_miller/lesson01/activity/calculator/divider.py b/students/jesse_miller/lesson01/activity/calculator/divider.py new file mode 100644 index 0000000..c169556 --- /dev/null +++ b/students/jesse_miller/lesson01/activity/calculator/divider.py @@ -0,0 +1,16 @@ +#!/usr/bin/env python3 +''' +Division module for calculator +''' +#pylint: disable=R0903 +class Divider(): + ''' + Division class for a more complex calculator + ''' + + @staticmethod + def calc(operand_1, operand_2): + ''' + This does the heavy lifting for division + ''' + return operand_1 / operand_2 diff --git a/students/jesse_miller/lesson01/activity/calculator/exceptions.py b/students/jesse_miller/lesson01/activity/calculator/exceptions.py new file mode 100644 index 0000000..539e110 --- /dev/null +++ b/students/jesse_miller/lesson01/activity/calculator/exceptions.py @@ -0,0 +1,3 @@ +#!/usr/bin/env python3 +class InsufficientOperands(Exception): + pass diff --git a/students/jesse_miller/lesson01/activity/calculator/multiplier.py b/students/jesse_miller/lesson01/activity/calculator/multiplier.py new file mode 100644 index 0000000..f5bbd81 --- /dev/null +++ b/students/jesse_miller/lesson01/activity/calculator/multiplier.py @@ -0,0 +1,16 @@ +#!/usr/bin/env python3 +''' +Multiplication module for calculator +''' +#pylint: disable=R0903 +class Multiplier(): + ''' + Multiplying class for a more complex calculator + ''' + + @staticmethod + def calc(operand_1, operand_2): + ''' + This does the heavy lifting for multiplying + ''' + return operand_1 * operand_2 diff --git a/students/jesse_miller/lesson01/activity/calculator/squarer.py b/students/jesse_miller/lesson01/activity/calculator/squarer.py new file mode 100644 index 0000000..60512f8 --- /dev/null +++ b/students/jesse_miller/lesson01/activity/calculator/squarer.py @@ -0,0 +1,14 @@ +#!/usr/bin/env python3 +class Squarer(object): + ''' + A simple squaring function + ''' + + @staticmethod + def calc(operand): + ''' + calculating the square + ''' + #return operand**2 # OLD + #return operand**operand # BAD + return operand*operand # This should work diff --git a/students/jesse_miller/lesson01/activity/calculator/subtracter.py b/students/jesse_miller/lesson01/activity/calculator/subtracter.py new file mode 100644 index 0000000..bb5e4ef --- /dev/null +++ b/students/jesse_miller/lesson01/activity/calculator/subtracter.py @@ -0,0 +1,16 @@ +#!/usr/bin/env python3 +''' +Subtraction module for calculator +''' +#pylint: disable=R0903 +class Subtracter(): + ''' + Addition class for a more complex calculator + ''' + + @staticmethod + def calc(operand_1, operand_2): + ''' + This does the heavy lifting for subtracting + ''' + return operand_1 - operand_2 diff --git a/students/jesse_miller/lesson01/activity/calculator/test.py b/students/jesse_miller/lesson01/activity/calculator/test.py new file mode 100644 index 0000000..0504b16 --- /dev/null +++ b/students/jesse_miller/lesson01/activity/calculator/test.py @@ -0,0 +1,109 @@ +#!/usr/bin/env python3 +#pylint: disable-all +from unittest import TestCase +from unittest.mock import MagicMock + +from adder import Adder +from subtracter import Subtracter +from multiplier import Multiplier +from divider import Divider +from calculator import Calculator +from exceptions import InsufficientOperands + +class AdderTests(TestCase): + def test_adding(self): + adder = Adder() + for i in range(-10, 10): + for j in range(-10, 10): + self.assertEqual(i + j, adder.calc(i, j)) + + +class SubtractorTests(TestCase): + def test_subtracting(self): + subtracter = Subtracter() + for i in range(-10, 10): + for j in range(-10, 10): + self.assertEqual(i - j, subtracter.calc(i, j)) + + +class MultiplierTests(TestCase): + def test_multiplying(self): + multiplier = Multiplier() + for i in range(-10, 10): + for j in range(-10, 10): + self.assertEqual(i * j, multiplier.calc(i, j)) + + +class DividerTests(TestCase): + def test_divider(self): + divider = Divider() + try: + for i in range(-10, 10): + for j in range(-10, 10): + self.assertEqual(i / j, divider.calc(i, j)) + except ZeroDivisionError: + return 0 + + +class CalculatorTests(TestCase): + + def setUp(self): + self.adder = Adder() + self.subtracter = Subtracter() + self.multiplier = Multiplier() + self.divider = Divider() + + self.calculator = Calculator(self.adder, self.subtracter, \ + self.multiplier, self.divider) + + + def test_insufficient_operands(self): + self.calculator.enter_number(0) + + with self.assertRaises(InsufficientOperands): + self.calculator.add() + + + def test_adder_call(self): + self.adder.calc = MagicMock(return_value=0) + + self.calculator.enter_number(1) + self.calculator.enter_number(2) + self.calculator.add() + + self.adder.calc.assert_called_with(1, 2) + + + def test_subtracter_call(self): + self.subtracter.calc = MagicMock(return_value=0) + + self.calculator.enter_number(1) + self.calculator.enter_number(2) + self.calculator.subtract() + + self.subtracter.calc.assert_called_with(1, 2) + + +class ModuleTests(TestCase): + + def test_module(self): + calculator = Calculator(Adder(), Subtracter(), Multiplier(), Divider()) + + calculator.enter_number(5) + calculator.enter_number(2) + + calculator.multiply() + + calculator.enter_number(46) + + calculator.add() + + calculator.enter_number(8) + + calculator.divide() + + calculator.enter_number(1) + + result = calculator.subtract() + + self.assertEqual(6, result) diff --git a/students/jesse_miller/lesson01/activity/squarer/squarer.py b/students/jesse_miller/lesson01/activity/squarer/squarer.py new file mode 100644 index 0000000..0d1028d --- /dev/null +++ b/students/jesse_miller/lesson01/activity/squarer/squarer.py @@ -0,0 +1,17 @@ +#!/usr/bin/env python3 +''' +Squaring module for our calculator +''' +class Squarer(): + ''' + A simple squaring function + ''' + + @staticmethod + def calc(operand): + ''' + calculating the square + ''' + #return operand**2 # OLD + #return operand**operand # BAD + return operand*operand # This should work diff --git a/students/jesse_miller/lesson01/activity/squarer/test.py b/students/jesse_miller/lesson01/activity/squarer/test.py new file mode 100644 index 0000000..30d5f91 --- /dev/null +++ b/students/jesse_miller/lesson01/activity/squarer/test.py @@ -0,0 +1,41 @@ +# 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() diff --git a/students/jesse_miller/lesson01/activity/squarer/test2.py b/students/jesse_miller/lesson01/activity/squarer/test2.py new file mode 100644 index 0000000..7810875 --- /dev/null +++ b/students/jesse_miller/lesson01/activity/squarer/test2.py @@ -0,0 +1,32 @@ +# 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)); diff --git a/students/jesse_miller/lesson01/activity/test_integration.py b/students/jesse_miller/lesson01/activity/test_integration.py new file mode 100755 index 0000000..bed8216 --- /dev/null +++ b/students/jesse_miller/lesson01/activity/test_integration.py @@ -0,0 +1,35 @@ +from unittest import TestCase +from unittest.mock import MagicMock + +from calculator.adder import Adder +from calculator.subtracter import Subtracter +from calculator.multiplier import Multiplier +from calculator.divider import Divider +from calculator.calculator import Calculator +from calculator.exceptions import InsufficientOperands + + +class ModuleTests(TestCase): + + def test_module(self): + + calculator = Calculator(Adder(), Subtracter(), Multiplier(), Divider()) + + calculator.enter_number(5) + calculator.enter_number(2) + + calculator.multiply() + + calculator.enter_number(46) + + calculator.add() + + calculator.enter_number(8) + + calculator.divide() + + calculator.enter_number(1) + + result = calculator.subtract() + + self.assertEqual(6, result) diff --git a/students/jesse_miller/lesson01/activity/test_unit.py b/students/jesse_miller/lesson01/activity/test_unit.py new file mode 100755 index 0000000..059f66e --- /dev/null +++ b/students/jesse_miller/lesson01/activity/test_unit.py @@ -0,0 +1,65 @@ +from unittest import TestCase +from unittest.mock import MagicMock + +from calculator.adder import Adder +from calculator.subtracter import Subtracter +from calculator.multiplier import Multiplier +from calculator.divider import Divider +from calculator.calculator import Calculator +from calculator.exceptions import InsufficientOperands + +class AdderTests(TestCase): + + def test_adding(self): + adder = Adder() + + for i in range(-10, 10): + for j in range(-10, 10): + self.assertEqual(i + j, adder.calc(i, j)) + + +class SubtracterTests(TestCase): + + def test_subtracting(self): + subtracter = Subtracter() + + for i in range(-10, 10): + for j in range(-10, 10): + self.assertEqual(i - j, subtracter.calc(i, j)) + + +class CalculatorTests(TestCase): + + def setUp(self): + self.adder = Adder() + self.subtracter = Subtracter() + self.multiplier = Multiplier() + self.divider = Divider() + + self.calculator = Calculator(self.adder, self.subtracter, self.multiplier, self.divider) + + def test_insufficient_operands(self): + self.calculator.enter_number(0) + + with self.assertRaises(InsufficientOperands): + self.calculator.add() + + def test_adder_call(self): + self.adder.calc = MagicMock(return_value=0) + + self.calculator.enter_number(1) + self.calculator.enter_number(2) + self.calculator.add() + + self.adder.calc.assert_called_with(1, 2) + + def test_subtracter_call(self): + self.subtracter.calc = MagicMock(return_value=0) + + self.calculator.enter_number(1) + self.calculator.enter_number(2) + self.calculator.subtract() + + self.subtracter.calc.assert_called_with(1, 2) + + diff --git a/students/jesse_miller/lesson01/assignment/README.md b/students/jesse_miller/lesson01/assignment/README.md new file mode 100755 index 0000000..95e6ab3 --- /dev/null +++ b/students/jesse_miller/lesson01/assignment/README.md @@ -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. diff --git a/students/jesse_miller/lesson01/assignment/inventory_management/electricAppliancesClass.py b/students/jesse_miller/lesson01/assignment/inventory_management/electricAppliancesClass.py new file mode 100755 index 0000000..291f199 --- /dev/null +++ b/students/jesse_miller/lesson01/assignment/inventory_management/electricAppliancesClass.py @@ -0,0 +1,22 @@ +# Electric appliances class +from inventoryClass import inventory + +class electricAppliances(inventory): + + def __init__(self, productCode, description, marketPrice, rentalPrice, brand, voltage): + inventory.__init__(self,productCode,description,marketPrice,rentalPrice) # Creates common instance variables from the parent class + + + self.brand = brand + self.voltage = voltage + + def returnAsDictionary(self): + outputDict = {} + outputDict['productCode'] = self.productCode + outputDict['description'] = self.description + outputDict['marketPrice'] = self.marketPrice + outputDict['rentalPrice'] = self.rentalPrice + outputDict['brand'] = self.brand + outputDict['voltage'] = self.voltage + + return outputDict \ No newline at end of file diff --git a/students/jesse_miller/lesson01/assignment/inventory_management/furnitureClass.py b/students/jesse_miller/lesson01/assignment/inventory_management/furnitureClass.py new file mode 100755 index 0000000..9a98aa7 --- /dev/null +++ b/students/jesse_miller/lesson01/assignment/inventory_management/furnitureClass.py @@ -0,0 +1,21 @@ +# Furniture class +from inventoryClass import inventory + +class furniture(inventory): + + def __init__(self, productCode, description, marketPrice, rentalPrice, material, size): + inventory.__init__(self,productCode,description,marketPrice,rentalPrice) # Creates common instance variables from the parent class + + self.material = material + self.size = size + + def returnAsDictionary(self): + outputDict = {} + outputDict['productCode'] = self.productCode + outputDict['description'] = self.description + outputDict['marketPrice'] = self.marketPrice + outputDict['rentalPrice'] = self.rentalPrice + outputDict['material'] = self.material + outputDict['size'] = self.size + + return outputDict \ No newline at end of file diff --git a/students/jesse_miller/lesson01/assignment/inventory_management/inventoryClass.py b/students/jesse_miller/lesson01/assignment/inventory_management/inventoryClass.py new file mode 100755 index 0000000..40c7fd3 --- /dev/null +++ b/students/jesse_miller/lesson01/assignment/inventory_management/inventoryClass.py @@ -0,0 +1,17 @@ +# Inventory class +class inventory: + + def __init__(self, productCode, description, marketPrice, rentalPrice): + self.productCode = productCode + self.description = description + self.marketPrice = marketPrice + self.rentalPrice = rentalPrice + + def returnAsDictionary(self): + outputDict = {} + outputDict['productCode'] = self.productCode + outputDict['description'] = self.description + outputDict['marketPrice'] = self.marketPrice + outputDict['rentalPrice'] = self.rentalPrice + + return outputDict \ No newline at end of file diff --git a/students/jesse_miller/lesson01/assignment/inventory_management/main.py b/students/jesse_miller/lesson01/assignment/inventory_management/main.py new file mode 100755 index 0000000..4b82694 --- /dev/null +++ b/students/jesse_miller/lesson01/assignment/inventory_management/main.py @@ -0,0 +1,69 @@ +# Launches the user interface for the inventory management system +import sys +import market_prices +import inventoryClass +import furnitureClass +import electricAppliancesClass + +def mainMenu(user_prompt=None): + valid_prompts = {"1": addNewItem, + "2": itemInfo, + "q": exitProgram} + options = list(valid_prompts.keys()) + + while user_prompt not in valid_prompts: + options_str = ("{}" + (", {}") * (len(options)-1)).format(*options) + print("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 getPrice(itemCode): + print("Get price") + +def addNewItem(): + global fullInventory + itemCode = input("Enter item code: ") + itemDescription = input("Enter item description: ") + itemRentalPrice = input("Enter item rental price: ") + + # Get price from the market prices module + itemPrice = market_prices.get_latest_price(itemCode) + + isFurniture = input("Is this item a piece of furniture? (Y/N): ") + if isFurniture.lower() == "y": + itemMaterial = input("Enter item material: ") + itemSize = input("Enter item size (S,M,L,XL): ") + newItem = furnitureClass.furniture(itemCode,itemDescription,itemPrice,itemRentalPrice,itemMaterial,itemSize) + else: + isElectricAppliance = input("Is this item an electric appliance? (Y/N): ") + if isElectricAppliance.lower() == "y": + itemBrand = input("Enter item brand: ") + itemVoltage = input("Enter item voltage: ") + newItem = electricAppliancesClass.electricAppliances(itemCode,itemDescription,itemPrice,itemRentalPrice,itemBrand,itemVoltage) + else: + newItem = inventoryClass.inventory(itemCode,itemDescription,itemPrice,itemRentalPrice) + fullInventory[itemCode] = newItem.returnAsDictionary() + print("New inventory item added") + + +def itemInfo(): + itemCode = input("Enter item code: ") + if itemCode in fullInventory: + printDict = fullInventory[itemCode] + for k,v in printDict.items(): + print("{}:{}".format(k,v)) + else: + print("Item not found in inventory") + +def exitProgram(): + sys.exit() + +if __name__ == '__main__': + fullInventory = {} + while True: + print(fullInventory) + mainMenu()() + input("Press Enter to continue...........") diff --git a/students/jesse_miller/lesson01/assignment/inventory_management/market_prices.py b/students/jesse_miller/lesson01/assignment/inventory_management/market_prices.py new file mode 100755 index 0000000..a486cc8 --- /dev/null +++ b/students/jesse_miller/lesson01/assignment/inventory_management/market_prices.py @@ -0,0 +1,3 @@ +def get_latest_price(item_code): + return 24 + # Raise an exception to force the user to Mock its output \ No newline at end of file diff --git a/students/jesse_miller/lesson01/assignment/pylintrc b/students/jesse_miller/lesson01/assignment/pylintrc new file mode 100644 index 0000000..0d96a23 --- /dev/null +++ b/students/jesse_miller/lesson01/assignment/pylintrc @@ -0,0 +1,236 @@ +[MASTER] + +# Specify a configuration file. +#rcfile= + +# Python code to execute, usually for sys.path manipulation such as +# pygtk.require(). +#init-hook= + +# Profiled execution. +profile=no + +# Add to the black list. It should be a base name, not a +# path. You may set this option multiple times. +ignore=CVS + +# Pickle collected data for later comparisons. +persistent=yes + +# List of plugins (as comma separated values of python modules names) to load, +# usually to register additional checkers. +load-plugins= + + +[MESSAGES CONTROL] + +# Enable the message, report, category or checker with the given id(s). You can +# either give multiple identifier separated by comma (,) or put this option +# multiple time. +#enable= + +# Disable the message, report, category or checker with the given id(s). You +# can either give multiple identifier separated by comma (,) or put this option +# multiple time. +disable= too-few-public-methods, too-many-arguments + + +[REPORTS] + +# Set the output format. Available formats are text, parseable, colorized, msvs +# (visual studio) and html +output-format=text + +# Include message's id in output +include-ids=no + +# Put messages in a separate file for each module / package specified on the +# command line instead of printing them on stdout. Reports (if any) will be +# written in a file name "pylint_global.[txt|html]". +files-output=no + +# Tells whether to display a full report or only the messages +reports=yes + +# Python expression which should return a note less than 10 (10 is the highest +# note). You have access to the variables errors warning, statement which +# respectively contain the number of errors / warnings messages and the total +# number of statements analyzed. This is used by the global evaluation report +# (R0004). +evaluation=10.0 - ((float(5 * error + warning + refactor + convention) / statement) * 10) + +# Add a comment according to your evaluation note. This is used by the global +# evaluation report (R0004). +comment=no + + +[VARIABLES] + +# Tells whether we should check for unused import in __init__ files. +init-import=no + +# A regular expression matching names used for dummy variables (i.e. not used). +dummy-variables-rgx=_|dummy + +# List of additional names supposed to be defined in builtins. Remember that +# you should avoid to define new builtins when possible. +additional-builtins= + + +[BASIC] + +# Required attributes for module, separated by a comma +required-attributes= + +# List of builtins function names that should not be used, separated by a comma +bad-functions=map,filter,apply,input + +# Regular expression which should only match correct module names +module-rgx=(([a-z_][a-z0-9_]*)|([A-Z][a-zA-Z0-9]+))$ + +# Regular expression which should only match correct module level names +const-rgx=(([A-Z_][A-Z0-9_]*)|(__.*__))$ + +# Regular expression which should only match correct class names +class-rgx=[A-Z_][a-zA-Z0-9]+$ + +# Regular expression which should only match correct function names +function-rgx=[a-z_][a-z0-9_]{2,30}$ + +# Regular expression which should only match correct method names +method-rgx=[a-z_][a-z0-9_]{2,30}$ + +# Regular expression which should only match correct instance attribute names +attr-rgx=[a-z_][a-z0-9_]{2,30}$ + +# Regular expression which should only match correct argument names +argument-rgx=[a-z_][a-z0-9_]{2,30}$ + +# Regular expression which should only match correct variable names +variable-rgx=[a-z_][a-z0-9_]{2,30}$ + +# Regular expression which should only match correct list comprehension / +# generator expression variable names +inlinevar-rgx=[A-Za-z_][A-Za-z0-9_]*$ + +# Good variable names which should always be accepted, separated by a comma +good-names=i,j,k,ex,Run,_ + +# Bad variable names which should always be refused, separated by a comma +bad-names=foo,bar,baz,toto,tutu,tata + +# Regular expression which should only match functions or classes name which do +# not require a docstring +no-docstring-rgx=__.*__ + + +[MISCELLANEOUS] + +# List of note tags to take in consideration, separated by a comma. +notes=FIXME,XXX,TODO + + +[FORMAT] + +# Maximum number of characters on a single line. +max-line-length=80 + +# Maximum number of lines in a module +max-module-lines=1000 + +# String used as indentation unit. This is usually " " (4 spaces) or "\t" (1 +# tab). +indent-string=' ' + + +[SIMILARITIES] + +# Minimum lines number of a similarity. +min-similarity-lines=4 + +# Ignore comments when computing similarities. +ignore-comments=yes + +# Ignore docstrings when computing similarities. +ignore-docstrings=yes + + +[TYPECHECK] + +# Tells whether missing members accessed in mixin class should be ignored. A +# mixin class is detected if its name ends with "mixin" (case insensitive). +ignore-mixin-members=yes + +# List of classes names for which member attributes should not be checked +# (useful for classes with attributes dynamically set). +ignored-classes=SQLObject + +# When zope mode is activated, add a predefined set of Zope acquired attributes +# to generated-members. +zope=no + +# List of members which are set dynamically and missed by pylint inference +# system, and so shouldn't trigger E0201 when accessed. +generated-members=REQUEST,acl_users,aq_parent + + +[DESIGN] + +# Maximum number of arguments for function / method +max-args=5 + +# Argument names that match this expression will be ignored. Default to name +# with leading underscore +ignored-argument-names=_.* + +# Maximum number of locals for function / method body +max-locals=15 + +# Maximum number of return / yield for function / method body +max-returns=6 + +# Maximum number of branch for function / method body +max-branchs=12 + +# Maximum number of statements in function / method body +max-statements=50 + +# Maximum number of parents for a class (see R0901). +max-parents=7 + +# Maximum number of attributes for a class (see R0902). +max-attributes=7 + +# Minimum number of public methods for a class (see R0903). +min-public-methods=2 + +# Maximum number of public methods for a class (see R0904). +max-public-methods=20 + + +[IMPORTS] + +# Deprecated modules which should not be used, separated by a comma +deprecated-modules=regsub,string,TERMIOS,Bastion,rexec + +# Create a graph of every (i.e. internal and external) dependencies in the +# given file (report RP0402 must not be disabled) +import-graph= + +# Create a graph of external dependencies in the given file (report RP0402 must +# not be disabled) +ext-import-graph= + +# Create a graph of internal dependencies in the given file (report RP0402 must +# not be disabled) +int-import-graph= + + +[CLASSES] + +# List of interface methods to ignore, separated by a comma. This is used for +# instance to not check methods defines in Zope's Interface base class. +ignore-iface-methods=isImplementedBy,deferred,extends,names,namesAndDescriptions,queryDescriptionFor,getBases,getDescriptionFor,getDoc,getName,getTaggedValue,getTaggedValueTags,isEqualOrExtendedBy,setTaggedValue,isImplementedByInstancesOf,adaptWith,is_implemented_by + +# List of method names used to declare (i.e. assign) instance attributes. +defining-attr-methods=__init__,__new__,setUp diff --git a/students/jesse_miller/lesson01/assignment/tests/README.md b/students/jesse_miller/lesson01/assignment/tests/README.md new file mode 100644 index 0000000..48cdce8 --- /dev/null +++ b/students/jesse_miller/lesson01/assignment/tests/README.md @@ -0,0 +1 @@ +placeholder From 29310714e447065b05cfd631eba8db4fc51301d9 Mon Sep 17 00:00:00 2001 From: UncleanlyCleric Date: Mon, 1 Apr 2019 23:45:54 -0700 Subject: [PATCH 07/11] So, moved my squarer and calculator to the proper dir, just FYI --- students/jesse_miller/lesson01/README.md | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 students/jesse_miller/lesson01/README.md diff --git a/students/jesse_miller/lesson01/README.md b/students/jesse_miller/lesson01/README.md new file mode 100644 index 0000000..e69de29 From 859c9d63290ebc9dd1882538108cff139faeec39 Mon Sep 17 00:00:00 2001 From: UncleanlyCleric Date: Mon, 1 Apr 2019 23:48:29 -0700 Subject: [PATCH 08/11] Removing bad directory --- .../jesse_miller/lesson01/calculator/adder.py | 15 ----- .../lesson01/calculator/calculator.py | 60 ------------------- .../lesson01/calculator/divider.py | 15 ----- .../lesson01/calculator/multiplier.py | 15 ----- .../lesson01/calculator/squarer.py | 14 ----- .../lesson01/calculator/subtractor.py | 15 ----- 6 files changed, 134 deletions(-) delete mode 100644 students/jesse_miller/lesson01/calculator/adder.py delete mode 100644 students/jesse_miller/lesson01/calculator/calculator.py delete mode 100644 students/jesse_miller/lesson01/calculator/divider.py delete mode 100644 students/jesse_miller/lesson01/calculator/multiplier.py delete mode 100644 students/jesse_miller/lesson01/calculator/squarer.py delete mode 100644 students/jesse_miller/lesson01/calculator/subtractor.py diff --git a/students/jesse_miller/lesson01/calculator/adder.py b/students/jesse_miller/lesson01/calculator/adder.py deleted file mode 100644 index 011a1ed..0000000 --- a/students/jesse_miller/lesson01/calculator/adder.py +++ /dev/null @@ -1,15 +0,0 @@ -#!/usr/bin/env python3 -''' -Addition module for calculator -''' -class Adder(): - ''' - Addition class for a more complex calculator - ''' - - @staticmethod - def calc(operand_1, operand_2): - ''' - This does the heavy lifting for adding - ''' - return operand_1 + operand_2 diff --git a/students/jesse_miller/lesson01/calculator/calculator.py b/students/jesse_miller/lesson01/calculator/calculator.py deleted file mode 100644 index 52454d0..0000000 --- a/students/jesse_miller/lesson01/calculator/calculator.py +++ /dev/null @@ -1,60 +0,0 @@ -#!/usr/bin/env python3 -''' -Our calculator -''' -class Calculator(): - ''' - Class base for the calculator - ''' - def __init__(self, adder, subtractor, multiplier, divider): - self.adder = adder - self.subtractor = subtractor - self.multiplier = multiplier - self.divider = divider - - self.stack = [] - - - def enter_number(self, number): - ''' - What it says on the tin. Enter a number. - ''' - self.stack.insert(0, number) - - - def _do_calc(self, operator): - ''' - Shortcut to operations on numbers. Keeps from having to repeat whole - functions. - ''' - result = operator.calc(self.stack[0], self.stack[1]) - self.stack = [result] - return result - - - def add(self): - ''' - Addition method - ''' - return self._do_calc(self.adder) - - - def subtract(self): - ''' - Subtraction method - ''' - return self._do_calc(self.subtractor) - - - def multiply(self): - ''' - Multiplication method - ''' - return self._do_calc(self.multiplier) - - - def divide(self): - ''' - Division method - ''' - return self._do_calc(self.divider) diff --git a/students/jesse_miller/lesson01/calculator/divider.py b/students/jesse_miller/lesson01/calculator/divider.py deleted file mode 100644 index 519590d..0000000 --- a/students/jesse_miller/lesson01/calculator/divider.py +++ /dev/null @@ -1,15 +0,0 @@ -#!/usr/bin/env python3 -''' -Division module for calculator -''' -class Divider(): - ''' - Division class for a more complex calculator - ''' - - @staticmethod - def calc(operand_1, operand_2): - ''' - This does the heavy lifting for division - ''' - return operand_1 / operand_2 diff --git a/students/jesse_miller/lesson01/calculator/multiplier.py b/students/jesse_miller/lesson01/calculator/multiplier.py deleted file mode 100644 index d5adf85..0000000 --- a/students/jesse_miller/lesson01/calculator/multiplier.py +++ /dev/null @@ -1,15 +0,0 @@ -#!/usr/bin/env python3 -''' -Multiplication module for calculator -''' -class Multiplier(): - ''' - Multiplying class for a more complex calculator - ''' - - @staticmethod - def calc(operand_1, operand_2): - ''' - This does the heavy lifting for multiplying - ''' - return operand_1 * operand_2 diff --git a/students/jesse_miller/lesson01/calculator/squarer.py b/students/jesse_miller/lesson01/calculator/squarer.py deleted file mode 100644 index 60512f8..0000000 --- a/students/jesse_miller/lesson01/calculator/squarer.py +++ /dev/null @@ -1,14 +0,0 @@ -#!/usr/bin/env python3 -class Squarer(object): - ''' - A simple squaring function - ''' - - @staticmethod - def calc(operand): - ''' - calculating the square - ''' - #return operand**2 # OLD - #return operand**operand # BAD - return operand*operand # This should work diff --git a/students/jesse_miller/lesson01/calculator/subtractor.py b/students/jesse_miller/lesson01/calculator/subtractor.py deleted file mode 100644 index 77efcbe..0000000 --- a/students/jesse_miller/lesson01/calculator/subtractor.py +++ /dev/null @@ -1,15 +0,0 @@ -#!/usr/bin/env python3 -''' -Subtraction module for calculator -''' -class Subtractor(): - ''' - Addition class for a more complex calculator - ''' - - @staticmethod - def calc(operand_1, operand_2): - ''' - This does the heavy lifting for subtracting - ''' - return operand_1 - operand_2 From 2086706193bcf5ba0b51f77d31c67cdf87ba9996 Mon Sep 17 00:00:00 2001 From: UncleanlyCleric Date: Tue, 2 Apr 2019 01:13:28 -0700 Subject: [PATCH 09/11] Cleaning up the nasty code, down to the parts I actually have to fix now --- .../electric_appliances.py | 38 +++++++ .../inventory_management/home_furniture.py | 32 ++++++ .../assignment/inventory_management/main.py | 103 +++++++++++------- .../inventory_management/market_prices.py | 4 +- .../inventory_management/store_inventory.py | 27 +++++ 5 files changed, 163 insertions(+), 41 deletions(-) create mode 100755 students/jesse_miller/lesson01/assignment/inventory_management/electric_appliances.py create mode 100755 students/jesse_miller/lesson01/assignment/inventory_management/home_furniture.py create mode 100755 students/jesse_miller/lesson01/assignment/inventory_management/store_inventory.py diff --git a/students/jesse_miller/lesson01/assignment/inventory_management/electric_appliances.py b/students/jesse_miller/lesson01/assignment/inventory_management/electric_appliances.py new file mode 100755 index 0000000..fccc2ec --- /dev/null +++ b/students/jesse_miller/lesson01/assignment/inventory_management/electric_appliances.py @@ -0,0 +1,38 @@ +#!/usr/bin/env python3 +''' +This class is for electric appliances +''' +from store_Inventory import Inventory + +class ElectricAppliances(Inventory): + ''' + Here we have the Inventory management for electric appliances, below it is + identified with product code, description, market and rental prices, brand, + and... voltage I guess. + ''' + + def __init__(self, product_code, description, market_price, rental_price, \ + brand, voltage): + ''' + Creates common instance variables from the parent class + ''' + Inventory.__init__(self, product_code, description, market_price,\ + rental_price) + + + self.brand = brand + self.voltage = voltage + + def return_as_dict(self): + ''' + Here we will populate the dictionary with the current Inventory numbers. + ''' + output_dict = {} + output_dict['product_code'] = self.product_code + output_dict['description'] = self.description + output_dict['market_price'] = self.market_price + output_dict['rental_price'] = self.rental_price + output_dict['brand'] = self.brand + output_dict['voltage'] = self.voltage + + return output_dict diff --git a/students/jesse_miller/lesson01/assignment/inventory_management/home_furniture.py b/students/jesse_miller/lesson01/assignment/inventory_management/home_furniture.py new file mode 100755 index 0000000..1c06b88 --- /dev/null +++ b/students/jesse_miller/lesson01/assignment/inventory_management/home_furniture.py @@ -0,0 +1,32 @@ +#!/usr/bin/env python3 +''' +This is the furniture class +''' +from store_inventory import inventory + +class FurnitureClass(inventory): + ''' + Creates common instance variables from the parent class + ''' + def __init__(self, product_code, description, market_price, rental_price, \ + material, size): + + inventory.__init__(self, product_code, description, market_price, \ + rental_price) + + self.material = material + self.size = size + + def return_as_dict(self): + ''' + Here we will populate the dictionary with the current inventory numbers. + ''' + output_dict = {} + output_dict['product_code'] = self.product_code + output_dict['description'] = self.description + output_dict['market_price'] = self.market_price + output_dict['rental_price'] = self.rental_price + output_dict['material'] = self.material + output_dict['size'] = self.size + + return output_dict diff --git a/students/jesse_miller/lesson01/assignment/inventory_management/main.py b/students/jesse_miller/lesson01/assignment/inventory_management/main.py index 4b82694..6ef9940 100755 --- a/students/jesse_miller/lesson01/assignment/inventory_management/main.py +++ b/students/jesse_miller/lesson01/assignment/inventory_management/main.py @@ -1,69 +1,92 @@ -# Launches the user interface for the inventory management system +#!/usr/bin/env python3 +''' +Launches the user interface for the Inventory management system +''' import sys import market_prices -import inventoryClass -import furnitureClass -import electricAppliancesClass +from store_inventory import Inventory +from home_furniture import FurnitureClass +from electric_appliances import ElectricAppliances -def mainMenu(user_prompt=None): - valid_prompts = {"1": addNewItem, - "2": itemInfo, - "q": exitProgram} +def main_menu(user_prompt=None): + ''' + Our main main + ''' + 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("Please choose from the following options ({options_str}):") - print("1. Add a new item to the inventory") + 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 getPrice(itemCode): +def get_price(item_code): + ''' + Prints "Get Price", otherwise doesn't seem to do anything... + ''' print("Get price") -def addNewItem(): - global fullInventory - itemCode = input("Enter item code: ") - itemDescription = input("Enter item description: ") - itemRentalPrice = input("Enter item rental price: ") +def add_new_item(): + ''' + Here we add a new individual item + ''' + + global full_inventory + 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 - itemPrice = market_prices.get_latest_price(itemCode) + item_price = market_prices.get_latest_price(item_code) - isFurniture = input("Is this item a piece of furniture? (Y/N): ") - if isFurniture.lower() == "y": - itemMaterial = input("Enter item material: ") - itemSize = input("Enter item size (S,M,L,XL): ") - newItem = furnitureClass.furniture(itemCode,itemDescription,itemPrice,itemRentalPrice,itemMaterial,itemSize) + 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 = FurnitureClass.furniture(item_code, item_description, \ + item_price, item_rental_price, item_material, item_size) else: - isElectricAppliance = input("Is this item an electric appliance? (Y/N): ") - if isElectricAppliance.lower() == "y": - itemBrand = input("Enter item brand: ") - itemVoltage = input("Enter item voltage: ") - newItem = electricAppliancesClass.electricAppliances(itemCode,itemDescription,itemPrice,itemRentalPrice,itemBrand,itemVoltage) + 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 = ElectricAppliances(item_code, \ + item_description, item_price, item_rental_price, item_brand, \ + item_voltage) else: - newItem = inventoryClass.inventory(itemCode,itemDescription,itemPrice,itemRentalPrice) - fullInventory[itemCode] = newItem.returnAsDictionary() - print("New inventory item added") + new_item = Inventory(item_code, item_description, \ + item_price, item_rental_price) + full_inventory[item_code] = new_item.return_as_dict() + print("New Inventory item added") -def itemInfo(): - itemCode = input("Enter item code: ") - if itemCode in fullInventory: - printDict = fullInventory[itemCode] - for k,v in printDict.items(): - print("{}:{}".format(k,v)) +def item_info(): + ''' + This is where we enter the item information for new product + ''' + item_code = input("Enter item code: ") + if item_code in full_inventory: + print_dict = full_inventory[item_code] + for k, v in print_dict.items(): + print("{}:{}".format(k, v)) else: - print("Item not found in inventory") + print("Item not found in Inventory") -def exitProgram(): +def exit_program(): + ''' + Gracefully exits + ''' sys.exit() if __name__ == '__main__': - fullInventory = {} + full_inventory = {} while True: - print(fullInventory) - mainMenu()() + print(full_inventory) + main_menu()() input("Press Enter to continue...........") diff --git a/students/jesse_miller/lesson01/assignment/inventory_management/market_prices.py b/students/jesse_miller/lesson01/assignment/inventory_management/market_prices.py index a486cc8..a1f6765 100755 --- a/students/jesse_miller/lesson01/assignment/inventory_management/market_prices.py +++ b/students/jesse_miller/lesson01/assignment/inventory_management/market_prices.py @@ -1,3 +1,5 @@ +#!/usr/bin/env python3 + def get_latest_price(item_code): return 24 - # Raise an exception to force the user to Mock its output \ No newline at end of file + # Raise an exception to force the user to Mock its output diff --git a/students/jesse_miller/lesson01/assignment/inventory_management/store_inventory.py b/students/jesse_miller/lesson01/assignment/inventory_management/store_inventory.py new file mode 100755 index 0000000..4b3f02f --- /dev/null +++ b/students/jesse_miller/lesson01/assignment/inventory_management/store_inventory.py @@ -0,0 +1,27 @@ +#!/usr/bin/env python3 +''' +This will be our inventory class +''' +class Inventory: + ''' + This class will track the inventory of the products housed + ''' + + def __init__(self, product_code, description, market_price, rental_price): + self.product_code = product_code + self.description = description + self.market_price = market_price + self.rental_price = rental_price + + def return_as_dict(self): + ''' + Here we will populate the dictionary with the current inventory numbers + for all departments. + ''' + output_dict = {} + output_dict['product_code'] = self.product_code + output_dict['description'] = self.description + output_dict['market_price'] = self.market_price + output_dict['rental_price'] = self.rental_price + + return output_dict From 66e6665709995ad125480615f0b949cf273a1212 Mon Sep 17 00:00:00 2001 From: UncleanlyCleric Date: Tue, 2 Apr 2019 01:50:23 -0700 Subject: [PATCH 10/11] It's complaining about R0801 disable being repeated in multiple files when I pylint the whole dir, but otherwise, this is clean and good to go... I think. --- .../electric_appliances.py | 15 +++--- .../inventory_management/home_furniture.py | 18 ++++--- .../assignment/inventory_management/main.py | 49 ++++++++++++------- .../inventory_management/market_prices.py | 2 + .../inventory_management/store_inventory.py | 3 ++ 5 files changed, 56 insertions(+), 31 deletions(-) diff --git a/students/jesse_miller/lesson01/assignment/inventory_management/electric_appliances.py b/students/jesse_miller/lesson01/assignment/inventory_management/electric_appliances.py index fccc2ec..6c20412 100755 --- a/students/jesse_miller/lesson01/assignment/inventory_management/electric_appliances.py +++ b/students/jesse_miller/lesson01/assignment/inventory_management/electric_appliances.py @@ -4,6 +4,9 @@ ''' from store_Inventory import Inventory + +# pylint: disable=R0903 +# pylint: disable=R0913 class ElectricAppliances(Inventory): ''' Here we have the Inventory management for electric appliances, below it is @@ -11,21 +14,21 @@ class ElectricAppliances(Inventory): and... voltage I guess. ''' - def __init__(self, product_code, description, market_price, rental_price, \ - brand, voltage): + def __init__(self, product_code, description, market_price, rental_price, + brand, voltage): ''' Creates common instance variables from the parent class ''' - Inventory.__init__(self, product_code, description, market_price,\ - rental_price) - + Inventory.__init__(self, product_code, description, market_price, + rental_price) self.brand = brand self.voltage = voltage def return_as_dict(self): ''' - Here we will populate the dictionary with the current Inventory numbers. + Here we will populate the dictionary with the current Inventory + numbers. ''' output_dict = {} output_dict['product_code'] = self.product_code diff --git a/students/jesse_miller/lesson01/assignment/inventory_management/home_furniture.py b/students/jesse_miller/lesson01/assignment/inventory_management/home_furniture.py index 1c06b88..8924e10 100755 --- a/students/jesse_miller/lesson01/assignment/inventory_management/home_furniture.py +++ b/students/jesse_miller/lesson01/assignment/inventory_management/home_furniture.py @@ -2,24 +2,28 @@ ''' This is the furniture class ''' -from store_inventory import inventory +from store_Inventory import Inventory -class FurnitureClass(inventory): + +# pylint: disable=R0913 +# pylint: disable=R0903 +class FurnitureClass(Inventory): ''' Creates common instance variables from the parent class ''' - def __init__(self, product_code, description, market_price, rental_price, \ - material, size): + def __init__(self, product_code, description, market_price, rental_price, + material, size): - inventory.__init__(self, product_code, description, market_price, \ - rental_price) + Inventory.__init__(self, product_code, description, market_price, + rental_price) self.material = material self.size = size def return_as_dict(self): ''' - Here we will populate the dictionary with the current inventory numbers. + Here we will populate the dictionary with the current Inventory + numbers. ''' output_dict = {} output_dict['product_code'] = self.product_code diff --git a/students/jesse_miller/lesson01/assignment/inventory_management/main.py b/students/jesse_miller/lesson01/assignment/inventory_management/main.py index 6ef9940..f7cea87 100755 --- a/students/jesse_miller/lesson01/assignment/inventory_management/main.py +++ b/students/jesse_miller/lesson01/assignment/inventory_management/main.py @@ -7,6 +7,11 @@ from store_inventory import Inventory from home_furniture import FurnitureClass from electric_appliances import ElectricAppliances +FULL_INVENTORY = {} +''' +I don't like globals, but right now I can't think of how to fix this. +''' + def main_menu(user_prompt=None): ''' @@ -15,10 +20,10 @@ def main_menu(user_prompt=None): valid_prompts = {"1": add_new_item, "2": item_info, "q": exit_program} - options = list(valid_prompts.keys()) + # options = list(valid_prompts.keys()) while user_prompt not in valid_prompts: - options_str = ("{}" + (", {}") * (len(options)-1)).format(*options) + # options_str = ("{}" + (", {}") * (len(options)-1)).format(*options) print("Please choose from the following options ({options_str}):") print("1. Add a new item to the Inventory") print("2. Get item information") @@ -26,18 +31,21 @@ def main_menu(user_prompt=None): user_prompt = input(">") return valid_prompts.get(user_prompt) + def get_price(item_code): ''' Prints "Get Price", otherwise doesn't seem to do anything... ''' - print("Get price") + # print("Get price") + latest_price = market_prices.get_latest_price(item_code) + return latest_price + def add_new_item(): ''' Here we add a new individual item ''' - - global full_inventory + # global full_inventory item_code = input("Enter item code: ") item_description = input("Enter item description: ") item_rental_price = input("Enter item rental price: ") @@ -49,20 +57,22 @@ def add_new_item(): if is_furniture.lower() == "y": item_material = input("Enter item material: ") item_size = input("Enter item size (S,M,L,XL): ") - new_item = FurnitureClass.furniture(item_code, item_description, \ - item_price, item_rental_price, item_material, item_size) + new_item = FurnitureClass(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): ") + 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 = ElectricAppliances(item_code, \ - item_description, item_price, item_rental_price, item_brand, \ - item_voltage) + new_item = ElectricAppliances(item_code, + item_description, item_price, + item_rental_price, item_brand, + item_voltage) else: - new_item = Inventory(item_code, item_description, \ - item_price, item_rental_price) - full_inventory[item_code] = new_item.return_as_dict() + new_item = Inventory(item_code, item_description, + item_price, item_rental_price) + FULL_INVENTORY[item_code] = new_item.return_as_dict() print("New Inventory item added") @@ -71,22 +81,25 @@ def item_info(): This is where we enter the item information for new product ''' item_code = input("Enter item code: ") - if item_code in full_inventory: - print_dict = full_inventory[item_code] + if item_code in FULL_INVENTORY: + print_dict = FULL_INVENTORY[item_code] + # pylint: disable=C0103 for k, v in print_dict.items(): print("{}:{}".format(k, v)) else: print("Item not found in Inventory") + def exit_program(): ''' Gracefully exits ''' sys.exit() + if __name__ == '__main__': - full_inventory = {} + # full_inventory = {} while True: - print(full_inventory) + print(FULL_INVENTORY) main_menu()() input("Press Enter to continue...........") diff --git a/students/jesse_miller/lesson01/assignment/inventory_management/market_prices.py b/students/jesse_miller/lesson01/assignment/inventory_management/market_prices.py index a1f6765..08ddcca 100755 --- a/students/jesse_miller/lesson01/assignment/inventory_management/market_prices.py +++ b/students/jesse_miller/lesson01/assignment/inventory_management/market_prices.py @@ -1,4 +1,6 @@ #!/usr/bin/env python3 +# pylint: disable=C0111 +# pylint: disable=W0613 def get_latest_price(item_code): return 24 diff --git a/students/jesse_miller/lesson01/assignment/inventory_management/store_inventory.py b/students/jesse_miller/lesson01/assignment/inventory_management/store_inventory.py index 4b3f02f..ac04798 100755 --- a/students/jesse_miller/lesson01/assignment/inventory_management/store_inventory.py +++ b/students/jesse_miller/lesson01/assignment/inventory_management/store_inventory.py @@ -2,6 +2,9 @@ ''' This will be our inventory class ''' + + +# pylint: disable=R0903 class Inventory: ''' This class will track the inventory of the products housed From 63162e2f4dfa86d6a85e487057c05aa216b81974 Mon Sep 17 00:00:00 2001 From: UncleanlyClericr Date: Tue, 2 Apr 2019 04:54:09 -0700 Subject: [PATCH 11/11] Fixing typos, cleaning up dir --- .../electricAppliancesClass.py | 22 ------------------- .../electric_appliances.py | 2 +- .../inventory_management/furnitureClass.py | 21 ------------------ .../inventory_management/home_furniture.py | 2 +- .../inventory_management/inventoryClass.py | 17 -------------- 5 files changed, 2 insertions(+), 62 deletions(-) delete mode 100755 students/jesse_miller/lesson01/assignment/inventory_management/electricAppliancesClass.py delete mode 100755 students/jesse_miller/lesson01/assignment/inventory_management/furnitureClass.py delete mode 100755 students/jesse_miller/lesson01/assignment/inventory_management/inventoryClass.py diff --git a/students/jesse_miller/lesson01/assignment/inventory_management/electricAppliancesClass.py b/students/jesse_miller/lesson01/assignment/inventory_management/electricAppliancesClass.py deleted file mode 100755 index 291f199..0000000 --- a/students/jesse_miller/lesson01/assignment/inventory_management/electricAppliancesClass.py +++ /dev/null @@ -1,22 +0,0 @@ -# Electric appliances class -from inventoryClass import inventory - -class electricAppliances(inventory): - - def __init__(self, productCode, description, marketPrice, rentalPrice, brand, voltage): - inventory.__init__(self,productCode,description,marketPrice,rentalPrice) # Creates common instance variables from the parent class - - - self.brand = brand - self.voltage = voltage - - def returnAsDictionary(self): - outputDict = {} - outputDict['productCode'] = self.productCode - outputDict['description'] = self.description - outputDict['marketPrice'] = self.marketPrice - outputDict['rentalPrice'] = self.rentalPrice - outputDict['brand'] = self.brand - outputDict['voltage'] = self.voltage - - return outputDict \ No newline at end of file diff --git a/students/jesse_miller/lesson01/assignment/inventory_management/electric_appliances.py b/students/jesse_miller/lesson01/assignment/inventory_management/electric_appliances.py index 6c20412..d666b02 100755 --- a/students/jesse_miller/lesson01/assignment/inventory_management/electric_appliances.py +++ b/students/jesse_miller/lesson01/assignment/inventory_management/electric_appliances.py @@ -2,7 +2,7 @@ ''' This class is for electric appliances ''' -from store_Inventory import Inventory +from store_inventory import Inventory # pylint: disable=R0903 diff --git a/students/jesse_miller/lesson01/assignment/inventory_management/furnitureClass.py b/students/jesse_miller/lesson01/assignment/inventory_management/furnitureClass.py deleted file mode 100755 index 9a98aa7..0000000 --- a/students/jesse_miller/lesson01/assignment/inventory_management/furnitureClass.py +++ /dev/null @@ -1,21 +0,0 @@ -# Furniture class -from inventoryClass import inventory - -class furniture(inventory): - - def __init__(self, productCode, description, marketPrice, rentalPrice, material, size): - inventory.__init__(self,productCode,description,marketPrice,rentalPrice) # Creates common instance variables from the parent class - - self.material = material - self.size = size - - def returnAsDictionary(self): - outputDict = {} - outputDict['productCode'] = self.productCode - outputDict['description'] = self.description - outputDict['marketPrice'] = self.marketPrice - outputDict['rentalPrice'] = self.rentalPrice - outputDict['material'] = self.material - outputDict['size'] = self.size - - return outputDict \ No newline at end of file diff --git a/students/jesse_miller/lesson01/assignment/inventory_management/home_furniture.py b/students/jesse_miller/lesson01/assignment/inventory_management/home_furniture.py index 8924e10..1ec3688 100755 --- a/students/jesse_miller/lesson01/assignment/inventory_management/home_furniture.py +++ b/students/jesse_miller/lesson01/assignment/inventory_management/home_furniture.py @@ -2,7 +2,7 @@ ''' This is the furniture class ''' -from store_Inventory import Inventory +from store_inventory import Inventory # pylint: disable=R0913 diff --git a/students/jesse_miller/lesson01/assignment/inventory_management/inventoryClass.py b/students/jesse_miller/lesson01/assignment/inventory_management/inventoryClass.py deleted file mode 100755 index 40c7fd3..0000000 --- a/students/jesse_miller/lesson01/assignment/inventory_management/inventoryClass.py +++ /dev/null @@ -1,17 +0,0 @@ -# Inventory class -class inventory: - - def __init__(self, productCode, description, marketPrice, rentalPrice): - self.productCode = productCode - self.description = description - self.marketPrice = marketPrice - self.rentalPrice = rentalPrice - - def returnAsDictionary(self): - outputDict = {} - outputDict['productCode'] = self.productCode - outputDict['description'] = self.description - outputDict['marketPrice'] = self.marketPrice - outputDict['rentalPrice'] = self.rentalPrice - - return outputDict \ No newline at end of file