def test_activity_coalesce(self):
        ''' ensure that activity data is getting coalesced by _accumulateActivities '''
        svcA, svcB = TestTools.create_mock_services()
        recA = TestTools.create_mock_svc_record(svcA)
        recB = TestTools.create_mock_svc_record(svcB)
        actA = TestTools.create_random_activity(svcA, tz=pytz.timezone("America/Iqaluit"))
        actB = Activity()
        actB.StartTime = actA.StartTime.replace(tzinfo=None)
        actB.ServiceDataCollection = TestTools.create_mock_servicedatacollection(svcB)
        actA.Name = "Not this"
        actA.Private = True
        actB.Name = "Heya"
        actB.Type = ActivityType.Walking
        actA.CalculateUID()
        actB.CalculateUID()

        s = SynchronizationTask(None)
        s._activities = []
        s._accumulateActivities(recB, [copy.deepcopy(actB)])
        s._accumulateActivities(recA, [copy.deepcopy(actA)])

        self.assertEqual(len(s._activities), 1)
        act = s._activities[0]

        self.assertEqual(act.StartTime, actA.StartTime)
        self.assertEqual(act.EndTime, actA.EndTime)
        self.assertEqual(act.EndTime.tzinfo, actA.StartTime.tzinfo)
        self.assertEqual(act.StartTime.tzinfo, actA.StartTime.tzinfo)
        self.assertLapsListsEqual(act.Laps, actA.Laps)
        self.assertTrue(act.Private)  # Most restrictive setting
        self.assertEqual(act.Name, actB.Name)  # The first activity takes priority.
        self.assertEqual(act.Type, actB.Type)  # Same here.
        self.assertTrue(list(actB.ServiceDataCollection.keys())[0] in act.ServiceDataCollection)
        self.assertTrue(list(actA.ServiceDataCollection.keys())[0] in act.ServiceDataCollection)

        s._activities = []
        s._accumulateActivities(recA, [copy.deepcopy(actA)])
        s._accumulateActivities(recB, [copy.deepcopy(actB)])

        self.assertEqual(len(s._activities), 1)
        act = s._activities[0]

        self.assertEqual(act.StartTime, actA.StartTime)
        self.assertEqual(act.EndTime, actA.EndTime)
        self.assertEqual(act.EndTime.tzinfo, actA.StartTime.tzinfo)
        self.assertEqual(act.StartTime.tzinfo, actA.StartTime.tzinfo)
        self.assertLapsListsEqual(act.Laps, actA.Laps)
        self.assertEqual(act.Name, actA.Name)  # The first activity takes priority.
        self.assertEqual(act.Type, actB.Type)  # Exception: ActivityType.Other does not take priority
        self.assertTrue(list(actB.ServiceDataCollection.keys())[0] in act.ServiceDataCollection)
        self.assertTrue(list(actA.ServiceDataCollection.keys())[0] in act.ServiceDataCollection)

        # Similar activities should be coalesced (Hiking, Walking..)..
        actA.Type = ActivityType.Hiking
        s._activities = []
        s._accumulateActivities(recA, [copy.deepcopy(actA)])
        s._accumulateActivities(recB, [copy.deepcopy(actB)])

        self.assertEqual(len(s._activities), 1)
        act = s._activities[0]
        self.assertEqual(act.Type, actA.Type)  # Here, it will take priority.

        # Dissimilar should not..
        actA.Type = ActivityType.CrossCountrySkiing
        s._activities = []
        s._accumulateActivities(recA, [copy.deepcopy(actA)])
        s._accumulateActivities(recB, [copy.deepcopy(actB)])

        self.assertEqual(len(s._activities), 2)
        self.assertEqual(s._activities[0].Type, actB.Type)
        self.assertEqual(s._activities[1].Type, actA.Type)
dataset/ETHPy150Open cpfair/tapiriik/tapiriik/testing/sync.py/SyncTests.test_activity_coalesce/original