def assemble_chart_data(): """ Collect data/user input for new chart. Get classname from user, load class data, take chart data from user. Return values for chart_data_dict assembly: class_name: str chart_name: str chart_filename: str student_scores: dict chart_params: dict :return: tuple(str, str, str, dict, dict) """ class_name = select_classlist() # TODO: warn for empty classlist class_data_dict = load_class_data(class_name) student_scores: dict = take_score_data(class_name, class_data_dict) chart_name = take_chart_name() chart_filename = clean_for_filename(chart_name) chart_params = set_chart_params() # chart options here or before score entry, setting chart params, min, max scores etc return class_name, chart_name, chart_filename, student_scores, chart_params
def assemble_chart_data(loaded_class: Class) -> Tuple[str, str, dict, dict]: """ Collect data/user input for new chart. Get classname from user, if not provided, load class data, take chart data from user. Return values for chart_data_dict assembly: loaded_class: Class chart_name: str chart_filename: str student_scores: dict chart_params: dict :param loaded_class: str = None :return: tuple(str, str, dict, dict) """ student_scores: dict = take_score_data(loaded_class) chart_name = take_chart_name() chart_filename = clean_for_filename(chart_name) chart_params = set_chart_params() # chart options here or before score entry, setting chart params, min, max scores etc return chart_name, chart_filename, student_scores, chart_params
def test_take_chart_name_good_input(self, mocked_input, mocked_input_is_essentially_blank): mocked_input.return_value = self.test_good_chart_name mocked_input_is_essentially_blank.return_value = False assert take_chart_name() == self.test_good_chart_name mocked_input_is_essentially_blank.assert_called_once_with( self.test_good_chart_name)
def test_take_chart_name_initial_blank_inputs_unmocked( self, mocked_input, mocked_print): all_inputs = self.test_blank_chart_inputs + [self.test_good_chart_name] mocked_input.side_effect = all_inputs assert take_chart_name() == self.test_good_chart_name assert mocked_print.call_args_list == [ mock.call(self.blank_chart_name_print_stmt) for blank_input in self.test_blank_chart_inputs ]
def test_take_chart_name(self, monkeypatch, mocked_inputs, expected_return): """Test valid input returned, mocking validation.""" def mocked_input_is_essentially_blank(test_chart_name): """Presume last input will be accepted.""" if test_chart_name != mocked_inputs[-1]: return True return False monkeypatch.setattr(take_chart_data_UI, 'input_is_essentially_blank', mocked_input_is_essentially_blank) with patch('builtins.input', side_effect=mocked_inputs): assert take_chart_name() == expected_return
def test_take_chart_name_initial_blank_inputs( self, mocked_input, mocked_input_is_essentially_blank, mocked_print): all_inputs = self.test_blank_chart_inputs + [self.test_good_chart_name] mocked_input.side_effect = all_inputs mocked_input_is_essentially_blank.side_effect = [ True for blank_input in self.test_blank_chart_inputs ] + [False] assert take_chart_name() == self.test_good_chart_name assert mocked_input_is_essentially_blank.call_args_list == [ mock.call(chart_name_input) for chart_name_input in all_inputs ] assert mocked_print.call_args_list == [ mock.call(self.blank_chart_name_print_stmt) for blank_input in self.test_blank_chart_inputs ]
def test_take_chart_name_unmocked_validation(self, monkeypatch, mocked_inputs, expected_return): """Test valid input returned, without mocking validation.""" with patch('builtins.input', side_effect=mocked_inputs): assert take_chart_name() == expected_return
def test_take_chart_name_good_input_unmocked(self, mocked_input): mocked_input.return_value = self.test_good_chart_name assert take_chart_name() == self.test_good_chart_name