|
| 1 | +#!/usr/bin/env python |
| 2 | + |
1 | 3 | import csv |
2 | 4 | import datetime |
3 | 5 | import os |
4 | 6 | from struct import pack |
5 | 7 | import sys |
6 | 8 |
|
7 | 9 | from fitparse import FitFile |
8 | | -from fitparse.processors import UTC_REFERENCE |
| 10 | +from fitparse.processors import UTC_REFERENCE, StandardUnitsDataProcessor |
9 | 11 | from fitparse.records import BASE_TYPES |
10 | 12 | from fitparse.utils import calc_crc, FitEOFError, FitCRCError, FitHeaderError |
11 | 13 |
|
@@ -109,13 +111,13 @@ def test_component_field_accumulaters(self): |
109 | 111 | # TODO: abstract CSV parsing |
110 | 112 | csv_fp = open(testfile('compressed-speed-distance-records.csv'), 'r') |
111 | 113 | csv_file = csv.reader(csv_fp) |
112 | | - csv_file.__next__() # Consume header |
| 114 | + next(csv_file) # Consume header |
113 | 115 |
|
114 | 116 | f = FitFile(testfile('compressed-speed-distance.fit')) |
115 | 117 | f.parse() |
116 | 118 |
|
117 | 119 | records = f.get_messages(name='record') |
118 | | - empty_record = records.__next__() # Skip empty record for now (sets timestamp via header) |
| 120 | + empty_record = next(records) # Skip empty record for now (sets timestamp via header) |
119 | 121 |
|
120 | 122 | # File's timestamp record is < 0x10000000, so field returns seconds |
121 | 123 | self.assertEqual(empty_record.get_value('timestamp'), 17217864) |
@@ -230,7 +232,7 @@ def test_subfield_components(self): |
230 | 232 | def test_parsing_edge_500_fit_file(self): |
231 | 233 | csv_fp = open(testfile('garmin-edge-500-activitiy-records.csv'), 'r') |
232 | 234 | csv_messages = csv.reader(csv_fp) |
233 | | - field_names = csv_messages.__next__() # Consume header |
| 235 | + field_names = next(csv_messages) # Consume header |
234 | 236 |
|
235 | 237 | f = FitFile(testfile('garmin-edge-500-activitiy.fit')) |
236 | 238 | messages = f.get_messages(name='record') |
@@ -274,13 +276,13 @@ def test_parsing_edge_500_fit_file(self): |
274 | 276 | self.assertEqual(fit_value, csv_value) |
275 | 277 |
|
276 | 278 | try: |
277 | | - messages.__next__() |
| 279 | + next(messages) |
278 | 280 | self.fail(".FIT file had more than csv file") |
279 | 281 | except StopIteration: |
280 | 282 | pass |
281 | 283 |
|
282 | 284 | try: |
283 | | - csv_messages.__next__() |
| 285 | + next(csv_messages) |
284 | 286 | self.fail(".CSV file had more messages than .FIT file") |
285 | 287 | except StopIteration: |
286 | 288 | pass |
@@ -346,6 +348,18 @@ def test_valid_files(self): |
346 | 348 | 'sample-activity.fit'): |
347 | 349 | FitFile(testfile(x)).parse() |
348 | 350 |
|
| 351 | + def test_units_processor(self): |
| 352 | + for x in ('2013-02-06-12-11-14.fit', '2015-10-13-08-43-15.fit', |
| 353 | + 'Activity.fit', 'Edge810-Vector-2013-08-16-15-35-10.fit', |
| 354 | + 'MonitoringFile.fit', 'Settings.fit', 'Settings2.fit', |
| 355 | + 'WeightScaleMultiUser.fit', 'WeightScaleSingleUser.fit', |
| 356 | + 'WorkoutCustomTargetValues.fit', 'WorkoutIndividualSteps.fit', |
| 357 | + 'WorkoutRepeatGreaterThanStep.fit', 'WorkoutRepeatSteps.fit', |
| 358 | + 'activity-large-fenxi2-multisport.fit', 'activity-small-fenix2-run.fit', |
| 359 | + 'antfs-dump.63.fit', 'sample-activity-indoor-trainer.fit', |
| 360 | + 'sample-activity.fit'): |
| 361 | + FitFile(testfile(x), data_processor=StandardUnitsDataProcessor()).parse() |
| 362 | + |
349 | 363 | # TODO: |
350 | 364 | # * Test Processors: |
351 | 365 | # - process_type_<>, process_field_<>, process_units_<>, process_message_<> |
|
0 commit comments