def test_access_attributes(self): song = MPDSong({'foo': 'zz', 'id': '5'}) self.assertEqual(5, song.id) self.assertEqual("zz", song.foo) self.assertIsInstance(song.foo, str) self.assertEqual(song.foo, song.get("foo"))
def test_access_attributes(self): song = MPDSong({"foo": "zz", "id": "5"}) self.assertEqual(5, song.id) self.assertEqual("zz", song.foo) self.assertIsInstance(song.foo, str) self.assertEqual(song.foo, song.get("foo"))
def test_get_unknown_attribute(self): song = MPDSong({}) self.assertRaises(KeyError, lambda: song['bla']) self.assertEqual(None, song.get('bla')) self.assertEqual('foo', song.get('bla', 'foo')) self.assertEqual(None, song.bla)
def test_get_unknown_attribute(self): song = MPDSong({}) self.assertRaises(KeyError, lambda: song["bla"]) self.assertEqual(None, song.get("bla")) self.assertEqual("foo", song.get("bla", "foo")) self.assertEqual(None, song.bla)