I have a python function that asks if the user wants to use the current file or select a new one. I need to check this out. Here is the function:
def file_checker(self):
file_change = raw_input('If you want to overwite existing file ?(Y/N) ')
if (file_change == 'y') or (file_change == 'Y') or (file_change == 'yes'):
logging.debug('overwriting existing file')
elif file_change.lower() == 'n' or (file_change == 'no'):
self.file_name = raw_input('enter new file name: ')
logging.debug('created a new file')
else:
raise ValueError('You must chose yes/no, exiting')
return os.path.join(self.work_dir, self.file_name)
I don’t take part when the user selects “yes”, but I don’t know how to check the “no” part:
def test_file_checker(self):
with mock.patch('__builtin__.raw_input', return_value='yes'):
assert self.class_obj.file_checker() == self.fname
with mock.patch('__builtin__.raw_input', return_value='no'):
source
share