Guest User

Untitled

a guest
Mar 21st, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.56 KB | None | 0 0
  1. import builtins
  2. import unittest
  3.  
  4.  
  5. def main():
  6. return int(input('Enter number: '))
  7.  
  8.  
  9. class TestMethods(unittest.TestCase):
  10. def setUp(self):
  11. # let's store original function somewhere
  12. self.original_input = builtins.input
  13.  
  14. def test(self):
  15. # we are replacing built-in function input() with our own function
  16. builtins.input = lambda x: '2'
  17. self.assertEqual(main(), 2)
  18.  
  19. def tearDown(self):
  20. # let's restore original function
  21. builtins.input = self.original_input
  22.  
  23.  
  24. if __name__ == '__main__':
  25. unittest.main()
Add Comment
Please, Sign In to add comment