Advertisement
Guest User

Untitled

a guest
Sep 17th, 2014
257
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. def main():
  2.  
  3. pirateList = []
  4. maxLengthList = 6
  5.  
  6. while len(pirateList) < maxLengthList:
  7. item = input("Argh! Enter the item: ")
  8.  
  9. if item == "exit":
  10. break;
  11. else:
  12. pirateList.append(item)
  13. print(pirateList)
  14.  
  15.  
  16. print(pirateList)
  17.  
  18.  
  19. main()
  20.  
  21. import unittest
  22. from unittest.mock import patch
  23. import io
  24. import sys
  25. from RunFile import main
  26.  
  27. class GetInputTest(unittest.TestCase):
  28.  
  29. @patch('builtins.input', side_effect=["bow", "arrow","exit"])
  30. def test_output(self,m):
  31. saved_stdout = sys.stdout
  32. try:
  33. out = io.StringIO()
  34. sys.stdout = out
  35. main()
  36. output = out.getvalue().strip()
  37. assert output.endswith('[bow, arrow]')
  38. finally:
  39. sys.stdout = saved_stdout
  40.  
  41.  
  42. if __name__ == "__main__":
  43. unittest.main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement