def set_unlock_previous(self, unlock_previous): """use a string -- for now, ``always`` and ``never`` are the options""" if unlock_previous is None: raise NullArgument('unlock_previous cannot be None') if unlock_previous is not None and not utilities.is_string( unlock_previous): raise InvalidArgument('unlock_previous must be a string') self.my_osid_object_form._my_map['unlockPrevious'] = unlock_previous
def set_difficulty(self, difficulty): """stub""" if not is_string(difficulty): raise InvalidArgument('difficulty value must be a string') if difficulty.lower() not in ['low', 'medium', 'hard']: raise InvalidArgument( 'difficulty value must be low, medium, or hard') self.my_osid_object_form._my_map['texts']['difficulty'][ 'text'] = difficulty
def add_choice(self, text, name='', identifier=None): """stub""" if not utilities.is_string(text): raise InvalidArgument('text is not a string') choice_display_text = self._choice_text_metadata[ 'default_string_values'][0] choice_display_text['text'] = text if identifier is None: identifier = str(ObjectId()) choice = {'id': identifier, 'text': text, 'name': name} self.my_osid_object_form._my_map['choices'].append(choice) return choice
def set_solution(self, text): """stub""" if not self.my_osid_object_form._is_valid_string( text, self.get_solution_metadata()): raise InvalidArgument('text') if is_string(text): self.my_osid_object_form._my_map['solution'] = { 'text': text, 'languageTypeId': str(DEFAULT_LANGUAGE_TYPE), 'scriptTypeId': str(DEFAULT_SCRIPT_TYPE), 'formatTypeId': str(DEFAULT_FORMAT_TYPE) } else: self.my_osid_object_form._my_map['solution'] = text
def __init__(self, hexstr=None, values=None, uncertainty_minus=None, uncertainty_plus=None): if values is not None: if not isinstance(values, list) or len(values) != 3: raise InvalidArgument() self._values = values elif hexstr is not None: if not is_string(hexstr) or len(hexstr) != 6: raise InvalidArgument() try: self._values = [ int(hexstr[:-4], 16), int(hexstr[2:-2], 16), int(hexstr[4:], 16) ] except: raise InvalidArgument(hexstr) else: raise NullArgument() self._uncertainty_minus = uncertainty_minus self._uncertainty_plus = uncertainty_plus
def set_source(self, source): """stub""" if not is_string(source): raise InvalidArgument('source value must be a string') self.my_osid_object_form._my_map['texts']['source']['text'] = source
def test_can_get_unlock_previous(self): self.assertTrue(dlkit_utilities.is_string(self.prev_button_object.get_unlock_previous())) self.assertEqual(self.prev_button_object.get_unlock_previous(), 'always')