コード例 #1
0
    def test_accessor_works(self):
        with ensure_removed(Activity, 'mine'):
            field.register_field('mine')(MyField)

            a = Activity(pd.DataFrame.from_dict({'mine': [1, 2]}))
            self.assertIs(a.mine.obj, a)

            self.assertEqual(a.mine.prop, 'item')
            self.assertEqual(a.mine.method(), 'item')
コード例 #2
0
    def test_raises_attribute_error(self):

        with ensure_removed(Activity, 'bad'):

            @field.register_field('bad')
            class Bad:
                def __init__(self, data):
                    raise AttributeError('whoops')

            with self.assertRaises(AttributeError, msg='whoops'):
                Activity(pd.DataFrame([], dtype=object)).bad
コード例 #3
0
 def test_overwrite_warns(self):
     # Need to restore at the end
     records_unique = Activity.records_unique
     try:
         with tm.assert_produces_warning(UserWarning) as w:
             field.register_field('records_unique')(MyField)
             a = Activity(pd.DataFrame.from_dict({'mine': [1, 2]}))
             self.assertEqual(a.records_unique.prop, 'item')
         msg = str(w[0].message)
         self.assertIn('records_unique', msg)
         self.assertIn('MyField', msg)
         self.assertIn('Activity', msg)
     finally:
         Activity.records_unique = records_unique
コード例 #4
0
    def test_timer(self):
        activity = heartandsole.Activity(
            pd.DataFrame([]),
            summary=pd.Series({
                'time_timer': 300.0,
            }),
            laps=pd.DataFrame.from_dict({
                'time_timer': [200.0, 150.0],
            }),
        )

        self.assertEqual(activity.time.timer('summary'), 300)
        self.assertEqual(activity.time.timer('laps'), 350)

        activity_blank = Activity(pd.DataFrame([]))
        for src in ['summary', 'laps']:
            self.assertIsNone(activity_blank.time.timer(src))
コード例 #5
0
    def test_elapsed(self):
        t0 = datetime.datetime.now()
        activity = heartandsole.Activity(
            pd.DataFrame.from_dict({
                'timestamp':
                [t0 + datetime.timedelta(seconds=s) for s in (0, 50, 75, 100)],
                'time': [0, 100, 200, 400],
            }),
            summary=pd.Series({
                'time_elapsed':
                300.0,
                'timestamp_start':
                t0,
                'timestamp_end':
                t0 + datetime.timedelta(seconds=101)
            }),
            laps=pd.DataFrame.from_dict({
                'time_elapsed': [200.0, 150.0],
                'timestamp_start': [t0, t0 + datetime.timedelta(seconds=49)],
                'timestamp_end': [
                    t0 + datetime.timedelta(seconds=49),
                    t0 + datetime.timedelta(seconds=99)
                ],
            }),
        )

        self.assertEqual(
            activity.timestamp.elapsed('records'),  # pd.Timedelta
            datetime.timedelta(seconds=100))
        self.assertEqual(
            activity.timestamp.elapsed('summary'),  # dt.timedelta
            datetime.timedelta(seconds=101))
        self.assertEqual(
            activity.timestamp.elapsed('laps'),  # pd.Timedelta
            datetime.timedelta(seconds=99))
        self.assertEqual(activity.time.elapsed('records'), 400)
        self.assertEqual(activity.time.elapsed('summary'), 300)
        self.assertEqual(activity.time.elapsed('laps'), 350)

        activity_blank = Activity(pd.DataFrame([]))
        for src in ['records', 'summary', 'laps']:
            self.assertIsNone(activity_blank.time.elapsed(src))
            self.assertIsNone(activity_blank.timestamp.elapsed(src))
コード例 #6
0
 def setUpClass(cls):
     cls.act = Activity.from_csv(cls.TESTDATA_FILENAME)
コード例 #7
0
 def setUpClass(cls):
     cls.fit = Activity.from_fit(TestFit.TESTDATA_FILENAME)
     cls.tcx = Activity.from_tcx(TestTcx.TESTDATA_FILENAME)
     cls.gpx = Activity.from_gpx(TestGpx.TESTDATA_FILENAME)