def test_to_list(self): lists = [['Teacher name', ['7333'], '122', True], ['Teacher name', ['2780.2'], 'КВАНТ-КК', True], ['Teacher name', [], '', False]] for (l, init_value) in zip(lists, self.init_values): lecture = Lecture.cell_parser(init_value) self.assertEqual(l, lecture.to_list(teacher_name='Teacher name'))
def df_parser(teacher_df): """ Парсит входные данные из листа с занятиями преподавателя и возвращает объект типа Преподаватель :param: pd.DataFrame :return: Teacher """ teacher = Teacher() teacher._df = teacher_df teacher._dates = [] teacher._pairs = {} months = [ 'сентября', 'октября', 'ноября', 'декабря', 'января', 'февраля', 'марта', 'апреля', 'мая', 'июня', 'июля', 'августа' ] for col_num in teacher._df.columns: dates = [] selected_rows = [] rows_num = len(teacher._df.index) + 1 for row_num, row in teacher._df.iterrows(): cell = row[col_num] try: if cell.split(' ')[1] in months: dates.append(cell) selected_rows.append(row_num + 1) except: pass teacher._dates += dates selected_rows.append(rows_num) for i, date in enumerate(dates): pairs_df = teacher._df[col_num][ selected_rows[i]:selected_rows[i + 1] - 1] pairs = pairs_df.replace(pd.np.nan, '') teacher._pairs[date] = [ Lecture.cell_parser(pair) for pair in pairs ] for date in teacher._pairs: teacher._pairs[date] = Teacher.parse_pairs(teacher._pairs[date]) return teacher
def test_get_pairs_dict(self): pairs_list = [{ '11 сентября': [ Lecture.cell_parser(''), Lecture.cell_parser(''), Lecture.cell_parser( 'Безопасность ОС:\nПЗ-15 ауд. 122\nгр. 7334'), Lecture.cell_parser(''), ] }, { '02 октября': [ Lecture.cell_parser(''), Lecture.cell_parser(''), Lecture.cell_parser( 'Безопасность ОС: \nлаб.раб-1 ауд. 122\nгр. 7334'), Lecture.cell_parser( 'Безопасность ОС: \nсем.-1 ауд. 209\nгр. 7334'), ] }, { '06 ноября': [ Lecture.cell_parser(''), Lecture.cell_parser(''), Lecture.cell_parser(''), Lecture.cell_parser(''), ] }] for (pairs, df) in zip(pairs_list, self.init_dataframes): teacher = Teacher.df_parser(df) self.assertEqual(pairs, teacher.get_pairs_dict())
def test_groups(self): groups = [['7333'], ['2780.2'], []] for (groups, init_value) in zip(groups, self.init_values): lecture = Lecture.cell_parser(init_value) self.assertEqual(groups, lecture.get_groups())
def test_names(self): names = ['Безопасность ОС', '2780', ''] for (name, init_value) in zip(names, self.init_values): lecture = Lecture.cell_parser(init_value) self.assertEqual(name, lecture.get_name())
def test_types(self): types = ['ПЗ', 'ПЗ', ''] for (tp, init_value) in zip(types, self.init_values): lecture = Lecture.cell_parser(init_value) self.assertEqual(tp, lecture.get_type())
def test_entry_value(self): for init_value in self.init_values: lecture = Lecture.cell_parser(init_value) self.assertEqual(init_value, lecture.get_full_value())
def test_comp_classes_flag(self): in_comp_classes = [True, True, False] for (flag, init_value) in zip(in_comp_classes, self.init_values): lecture = Lecture.cell_parser(init_value) self.assertEqual(flag, lecture.is_in_computer_class())
def test_classrooms(self): classrooms = ['122', 'КВАНТ-КК', ''] for (classroom, init_value) in zip(classrooms, self.init_values): lecture = Lecture.cell_parser(init_value) self.assertEqual(classroom, lecture.get_classroom())
def test_nums(self): nums = ['17', '6', ''] for (num, init_value) in zip(nums, self.init_values): lecture = Lecture.cell_parser(init_value) self.assertEqual(num, lecture.get_lecture_number())