2021年3月23日星期二

Python unittest a simple user input function without parameter

How would you unittest the following in Python?

  • I just want to unittest that the input is a string not an integer, float, or character.
  • self.assertRaises requires a parameter for the function but there are no arguments because the function just asks for an input.
def name():      account_name = input("Please enter your business name: ")      print('\n'*2)      return account_name    def nextstep(accts):      result = input("Would you like to make a deposit or withdrawal?: ").lower()      if result.startswith("d"):          amount = int(input("Enter an amount to deposit: "))          accts.deposit(amount)      if result.startswith("w"):          amount = int(input("Enter an amount to withdrawal: "))          accts.withdraw(amount)      return accts    def continue_step():      print('\n')      answer = input("Would you like to continue?: ").lower()      if answer.startswith("y"):          print("Yes")      else:          print("Bye")      return answer  
import unittest    class TestSample(unittest.TestCase):        def test_accountname(self):          self.assertRaises(TypeError, continue_step, parameter)            unittest.main()  
https://stackoverflow.com/questions/66759743/python-unittest-a-simple-user-input-function-without-parameter March 23, 2021 at 04:40PM

没有评论:

发表评论