def test_dual_transformer_regression_test(self): """DualTransformer has failed when there were multiple DualTransformers. It has also failed when DualTransformer was not the outermost transformer or when other transformers were between multiple DualTransformers.""" player = InterspersedDualTransformersNamePrefixAbsent() self.assert_orignal_equals_pickled(player) player = InterspersedDualTransformersNamePrefixPresent() self.assert_orignal_equals_pickled(player) player_class = axl.WinStayLoseShift player_class = st.DualTransformer()(player_class) player_class = st.InitialTransformer((C, D))(player_class) player_class = st.DualTransformer()(player_class) player_class = st.TrackHistoryTransformer()(player_class) interspersed_dual_transformers = player_class() self.assert_orignal_equals_pickled(interspersed_dual_transformers)
transformer_instances = [ st.ApologyTransformer([D], [C]), st.DeadlockBreakingTransformer(), st.DualTransformer(), st.FlipTransformer(), st.FinalTransformer((D, D)), st.ForgiverTransformer(0.2), st.GrudgeTransformer(3), st.InitialTransformer((C, D)), st.JossAnnTransformer((0.2, 0.6)), st.MixedTransformer(probability, strategies), st.NiceTransformer(), st.NoisyTransformer(0.2), st.RetaliationTransformer(3), st.RetaliateUntilApologyTransformer(), st.TrackHistoryTransformer(), st.IdentityTransformer(), ] class TestPickle(unittest.TestCase): def assert_equals_instance_from_pickling(self, original_instance): copy = pickle.loads(pickle.dumps(original_instance)) self.assertEqual(copy, original_instance) def assert_orignal_equals_pickled(self, player, turns=10): opponents = (axl.Defector, axl.Cooperator, axl.Random, axl.CyclerCCCDCD) for opponent_class in opponents: # Check that player and copy play the same way. player.reset() copy = pickle.loads(pickle.dumps(player))