Skip to content

Instantly share code, notes, and snippets.

@AndyLPK247
Created March 14, 2017 03:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save AndyLPK247/2ba5fc21c2243dcf4939a8e65cec3cd2 to your computer and use it in GitHub Desktop.
Save AndyLPK247/2ba5fc21c2243dcf4939a8e65cec3cd2 to your computer and use it in GitHub Desktop.
Python Testing 101 pytest Example: Calculator Class
from com.automationpanda.example.calc_func import *
class Calculator(object):
def __init__(self):
self._last_answer = 0.0
@property
def last_answer(self):
return self._last_answer
def _do_math(self, a, b, func):
self._last_answer = func(a, b)
return self.last_answer
def add(self, a, b):
return self._do_math(a, b, add)
def subtract(self, a, b):
return self._do_math(a, b, subtract)
def multiply(self, a, b):
return self._do_math(a, b, multiply)
def divide(self, a, b):
return self._do_math(a, b, divide)
def maximum(self, a, b):
return self._do_math(a, b, maximum)
def minimum(self, a, b):
return self._do_math(a, b, minimum)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment