def __init__(self, file: str): logging.debug('initialising DataReader... ') logging.debug('cwd: %s' % (os.getcwd())) self.file = file self.dataset = [] self.sessions = {} self.dates = [] with open(file, mode='r', newline='') as csv_file: self.reader = csv.reader(csv_file) for data in self.reader: self.dataset.append(data) # How about here, while we're reading in the data we translate and store in sessions. if datetime.strptime(data[0], '%Y/%m/%d') in self.sessions: # add this line to existing session exercise = Exercise(data[1], data[5]) # Translate reps from this line totalRepetitions, successfulRepetitions, failedRepetitions = self.translateRepetitions(data[2]) exercise.sets.append(Set(totalRepetitions, successfulRepetitions, failedRepetitions, int(data[3]))) # add exercise to this session self.sessions[datetime.strptime(data[0], '%Y/%m/%d')].addExercise(exercise) else: # add date to dates list and initialise the exercises list self.dates.append(data[0]) # create new session session = Session(datetime.strptime(data[0], '%Y/%m/%d')) exercise = Exercise(data[1], data[5]) # Translate reps from this line totalRepetitions, successfulRepetitions, failedRepetitions = self.translateRepetitions(data[2]) exercise.sets.append(Set(totalRepetitions, successfulRepetitions, failedRepetitions, int(data[3]))) # Add this exercise to this session, need to update addExercise to handle duplicates. session.addExercise(exercise) # Check if it's a competition session or not if data[4] != '': session.competition = True self.sessions[datetime.strptime(data[0], '%Y/%m/%d')] = session logging.debug('DataReader initialised')
class Test_Session(): def setup_method(self): logging.info('Setting up before test... ') self.session = Session(datetime(2020, 4, 1)) self.session.addExercise(Exercise('Snatch', 'Snatch')) def teardown_method(self): logging.info('Tearing down after test... ') self.session = None def test_session(self): expected = 'Snatch' result = self.session.exercises[0].name assert result == expected