Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
unittest
#1
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
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()
Reply


Messages In This Thread
unittest - by mepyyeti - Dec-21-2017, 01:49 AM
RE: unittest - by squenson - Dec-21-2017, 07:56 AM
RE: unittest - by snippsat - Dec-21-2017, 03:56 PM
RE: unittest - by mepyyeti - Dec-21-2017, 04:57 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Python Unittest roadrage 0 1,671 Feb-14-2019, 06:11 AM
Last Post: roadrage

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020