Dec-21-2017, 01:49 AM
So I'm working with Python and wanted to understand something specific to the unittest module. I'll include all snippets. please note that everything runs. My question is in the comment in the last snippet.
SNIPPET 1 OK
SNIPPET 1 OK
class SurveyTaker(): def __init__(self, query): self.query = query self.responses = [] def show_query(self): print(self.query) def update_resp(self, new_item): self.responses.append(new_item) print(new_item, '- uploaded.') def show_resp(self): for i in self.responses: print('- ', i)SNIPPET 2 OK
from asurvey2 import SurveyTaker title = 'Something grand'.upper() my_survey=SurveyTaker(title) while True: print('\'q\' to quit anytime') comment = str(input('say something. ')) if comment == 'q': break else: comment = my_survey.update_resp(comment) print('thx') my_survey.show_resp()SNIPPET 3 OK -- QUESTION I have is in this snippet regarding self.assertIn(foo, self.bar)....
#test_asurvey2.py import unittest from asurvey2 import SurveyTaker class TestIsh(unittest.TestCase): def testSurvey(self): titl = 'something said'.title() my_survey = SurveyTaker(titl) responses = [] for item in responses: my_survey.update_resp(item) ''' ''' for item in responses: #I would think line below should read -- self.assertIn(item, self.my_survey.responses) #or self.assertIn(item, self.my_survey.show_resp) ... self.assertIn(item, self.my_survey)#why does self.my_survey actually work? IDU this! unittest.main()