Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Abhishek-Srivastava/5520254 to your computer and use it in GitHub Desktop.
Save Abhishek-Srivastava/5520254 to your computer and use it in GitHub Desktop.
'''
Created on Apr 25, 2013
@author: abhsriva
'''
import unittest
import mox
from class_to_be_tested import Do_Mathematics
class Test_Do_Mathematics_class(unittest.TestCase):
def setUp(self):
print 'In setup', self.x
self.mock = mox.Mox()
self.do_maths = Do_Mathematics(10, 20)
def tearDown(self):
print 'In tear down', self.x
del self.do_maths
def test_sum(self):
result = self.do_maths.sum()
self.assertEqual(result, 30, "Sum method is incorrect")
def test_sub(self):
result = self.do_maths.sub()
self.assertEqual(result, -10, "Sub method is incorrect")
def test_div(self):
self.mock.StubOutWithMock(Do_Mathematics, '_check_if_zero')
self.do_maths._check_if_zero(mox.IgnoreArg()).AndReturn(False)
self.mock.ReplayAll()
result = self.do_maths.div()
self.mock.VerifyAll()
self.assertEqual(result, 0.5, "Div method is incorrect")
def test_check_greater_with_zero(self):
self.assertTrue(self.do_maths._check_if_zero(0))
def test_check_greater_non_zero(self):
self.assertFalse(self.do_maths._check_if_zero(10))
if __name__ == "__main__":
unittest.main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment