def __setstate__(self, dict): # Logger.info(u"track dict in: %s" % dict) artist = ArtistFactory.by_key(dict['artist_key']) del dict['artist_key'] ratingref = RatingFactory.by_key(dict['ratingref_key']) del dict['ratingref_key'] self.__dict__ = dict self.artist = artist self.ratingref = ratingref # Logger.info(u"track.dict out: %s" % self.__dict__) TrackFactory.register(self)
def __setstate__(self, dict): trackA = TrackFactory.by_key(dict['trackA_key']) del dict['trackA_key'] trackB = TrackFactory.by_key(dict['trackB_key']) del dict['trackB_key'] ratingref = RatingFactory.by_key(dict['ratingref_key']) del dict['ratingref_key'] self.__dict__ = dict self.trackA = trackA self.trackB = trackB self.ratingref = ratingref
def testRating(self): Factories.clear() """ test init """ rating = RatingFactory.get(0.7) rating.test = "init" self.assertEqual(rating.playcount, 0) self.assertEqual(rating.skipcount, 0) self.assertEqual(rating.playfactor, 0) self.assertEqual(rating.skipfactor, 0) self.assertEqual(rating.rating, 0.5) """ test update A """ ratingA = rating.played() ratingA.test = "A" """ verify old """ self.assertEqual(rating.playcount, 0) self.assertEqual(rating.skipcount, 0) self.assertEqual(rating.playfactor, 0) self.assertEqual(rating.skipfactor, 0) self.assertEqual(rating.rating, 0.5) """ verify new """ self.assertEqual(ratingA.playcount, 1) self.assertEqual(ratingA.skipcount, 0) self.assertEqual(ratingA.playfactor, 1.0) self.assertEqual(ratingA.skipfactor, 0) """ test update B """ ratingB = ratingA.skipped() ratingB.test = "B" """ verify old """ self.assertEqual(ratingA.playcount, 1) self.assertEqual(ratingA.skipcount, 0) self.assertEqual(ratingA.playfactor, 1.0) self.assertEqual(ratingA.skipfactor, 0) """ verify new """ self.assertEqual(ratingB.playcount, 1) self.assertEqual(ratingB.skipcount, 1) self.assertEqual(ratingB.playfactor, 1.0) self.assertEqual(ratingB.skipfactor, 1.0) self.assertEqual(ratingB.stable, 0.5) """ test update C """ ratingC = ratingB.played(0.5) ratingC.test = "C" """ verify old """ self.assertEqual(ratingB.playcount, 1) self.assertEqual(ratingB.skipcount, 1) self.assertEqual(ratingB.playfactor, 1.0) self.assertEqual(ratingB.skipfactor, 1.0) self.assertEqual(ratingB.stable, 0.5) """ verify new """ self.assertEqual(ratingC.playcount, 1) self.assertEqual(ratingC.skipcount, 1) self.assertEqual(ratingC.playfactor, 1.5) self.assertEqual(ratingC.skipfactor, 1.0) ratingD = ratingC.skipped(0.5) ratingD.test = "D" """ verify old """ self.assertEqual(ratingC.playcount, 1) self.assertEqual(ratingC.skipcount, 1) self.assertEqual(ratingC.playfactor, 1.5) self.assertEqual(ratingC.skipfactor, 1.0) """ verify new """ self.assertEqual(ratingD.playcount, 1) self.assertEqual(ratingD.skipcount, 1) self.assertEqual(ratingD.playfactor, 1.5) self.assertEqual(ratingD.skipfactor, 1.5) self.assertEqual(ratingD.stable, 0.5) """ references """ ratingE = RatingFactory.get(ratingD.mix, ratingD.slope, ratingD.playcount, ratingD.playfactor, ratingD.skipcount, ratingD.skipfactor, ratingD.rating, ratingD.rolling, ratingD.stable) self.assertEqual(ratingE.test, ratingD.test) ratingF = RatingFactory.by_key(ratingD.key()) self.assertEqual(ratingD.test, ratingF.test)