コード例 #1
0
	def testConstructor(self):
		m1 = proj1.Media()
		m2 = proj1.Media("1999", "Prince", 1982, "https://www.example-url-1999.com")
		self.assertEqual(m1.title, "No Title")
		self.assertEqual(m1.author, "No Author")
		self.assertEqual(m1.release_year, "No Release Year")
		self.assertEqual(m2.title, "1999")
		self.assertEqual(m2.author, "Prince")
		self.assertEqual(m2.release_year, 1982)
		self.assertEqual(m2.url, "https://www.example-url-1999.com")
		self.assertRaises(AttributeError, lambda: m2.album)
		self.assertRaises(AttributeError, lambda: m2.genre)
		self.assertRaises(AttributeError, lambda: m2.track_length)
		self.assertRaises(AttributeError, lambda: m2.rating)
		self.assertRaises(AttributeError, lambda: m2.movie_length)
コード例 #2
0
	def testMedia(self):
		f = open("sample_json.json","r")
		sample_data = json.loads(f.read())
		f.close()
		
		m = proj1.Media(json=sample_data[2])

		self.assertEqual(m.title, "Bridget Jones's Diary (Unabridged)")
		self.assertEqual(m.author, "Helen Fielding")
		self.assertEqual(m.release_year, "2012")
		self.assertEqual(m.url, "https://itunes.apple.com/us/audiobook/bridget-joness-diary-unabridged/id516799841?uo=4")
		self.assertEqual(m.info(), "Bridget Jones's Diary (Unabridged) by Helen Fielding (2012)")
		self.assertEqual(m.length(), 0)
コード例 #3
0
	def testInfo(self):
		m2 = proj1.Media("1999", "Prince", 1982)
		self.assertEqual(m2.info(), "1999 by Prince (1982)")
コード例 #4
0
	def testExample(self):
		m1 = proj1.Media("1999", "Prince")
		self.assertEqual(m1.title, "1999")
		self.assertEqual(m1.author, "Prince")