Package: calculator-mlotfic
Simple Calculator ModuleBuilding a python package using simple calculator programIn this repo you will git to know :How to build a python program into package?How tp publish your package to PyPi repo?How to create unit test and automate testing for python program?How to check for code quailty and styling using pylint on python program?How to using GitHub Action :Publish Python PackageBy GitHub ActionsPublish a Python Package to PyPI on release.PylintBy GitHub ActionsLint a Python application with pylint.Python applicationBy GitHub ActionsCreate and test a Python application.Python packageBy GitHub ActionsCreate and test a Python package on multiple Python versions.Program StructureDisplaying Interface Options# print the calculator interfaceprint("Select operation::")print("0. Exit")print("1. Add (+) ")print("2. Subtract (-)")print("3. Multiply (*)")print("4. Divide (/)")Interaction with userswhileTrue:# take input from the userchoice=input("Enter choice(0/1/2/3/4): ")# check if choice is one of the four optionsifchoicein('1','2','3','4'):x=(input("Enter first number: "))y=(input("Enter second number: "))# creating object from classcal=Calculator(x,y)ifchoice=='1':print("Result: ",cal.add())elifchoice=='2':print("Result: ",cal.sub())elifchoice=='3':print("Result: ",cal.mul())elifchoice=='4':print("Result: ",round(cal.div(),2))elifchoice=='0':print("Exiting!!")breakelse:print("Invalid Input, please try again")Class DefinitionclassCalculator():'''Create a class and using a constructor to initialize values of that class.'''def__init__(self,x,y):self.x=float(x)self.y=float(y)# This methos add two nubersdefadd(self):returnself.x+self.y# This methos subtracting two numbersdefsub(self):returnself.x-self.y# This methos multiplying two numbersdefmul(self):returnself.x*self.y# This methos dividing two numbersdefdiv(self):returnself.x/self.yUnit TestingA Typical directory structure for running tests usingpytestRef :stackoverflowThe best solution in my opinion is to use theunittestcommand line interfacewhich will add the directory to thesys.pathso you don't have to (done in theTestLoaderclass).For example for a directory structure like this:cal_project
├── calculator.py
└── test_calculator.pyYou can just run:$ cd new_project
$ python -m pytest test_antigravityFor a directory structure like yours:new_project
├── antigravity
│   ├── __init__.py         # make it a package
│   └── antigravity.py
└── test
    ├── __init__.py         # also make test a package
    └── test_antigravity.pyAnd in the test modules inside thetestpackage, you can import theantigravitypackage and its modules as usual:# import the package
import antigravity

# import the antigravity module
from antigravity import antigravity

# or an object inside the antigravity module
from antigravity.antigravity import my_objectRunning a single test module:To run a single test module, in this casetest_antigravity.py:$ cd new_project
$ python -m unittest test.test_antigravityJust reference the test module the same way you import it.Running a single test case or test method:Also you can run a singleTestCaseor a single test method:$ python -m unittest test.test_antigravity.GravityTestCase
$ python -m unittest test.test_antigravity.GravityTestCase.test_methodRunning all tests:You can also usetest discoverywhich will discover and run all the tests for you, they must be modules or packages namedtest*.py(can be changed with the-p, --patternflag):$ cd new_project
$ python -m unittest discoverThis will run all thetest*.pymodules inside thetestpackage.