Example #1
0
class TestCat(TestCase):
	"""Tests for shields.basic_oo_example.cat Cat"""

	def setUp(self):
		# create a Cat to test
		self.whiskers = Cat('Whiskers', 'Tabby', 'orange')

	def tearDown(self):
		del self.whiskers

	def test_stringRepresentations(self):
		# repr and str are qualitatively different
		self.assertFalse(repr(self.whiskers) is str(self.whiskers))
		# but repr should still return something of type string
		self.assertTrue(type(repr(self.whiskers)) is str)

	def test_speak(self):
		# make sure a string returns on speak
		meow = self.whiskers.speak()
		self.assertTrue(type(meow) is str)

	def test_emoji(self):
		# Cat's emoji should be the cat-face emoji
		# u prefix required because: u'\U0001f431' != '\xf0\x9f\x90\xb1'
		self.assertEqual(self.whiskers.__class__.emoji(), u'🐱')

	def test_name(self):
		# make sure the parent's name property works on this child
		self.assertEqual(self.whiskers.name, 'Whiskers')
		self.whiskers.name = 'Mittens'
		self.assertEqual(self.whiskers.name, 'Mittens')

	def test_scratch(self):
		# make sure that the cat scratch method returns a string
		scr = self.whiskers.scratch('the scratching post')
		self.assertTrue(type(scr) is str)
Example #2
0
	def setUp(self):
		# create a Cat to test
		self.whiskers = Cat('Whiskers', 'Tabby', 'orange')