def test_choices_update_options_with_scheme(self): scheme = Scheme(choices=["Cat", "Dog", "Fish"]) question = MultipleChoiceQuestion( "What?", choices=["Chicken"], scheme=scheme ) self.assertEqual( [ Option(value="a", expression="Chicken"), Option(value="b", expression="Cat"), Option(value="c", expression="Dog"), Option(value="d", expression="Fish"), ], question.get_options(), ) # External update new_scheme = Scheme(choices=["Cow"]) question.update_scheme(new_scheme) self.assertEqual( [ Option(value="a", expression="Chicken"), Option(value="b", expression="Cat"), Option(value="c", expression="Dog"), Option(value="d", expression="Fish"), Option(value="e", expression="Cow"), ], question.get_options(), ) self.assertEqual([], question.primitive_options)
def test_choices_combined_with_options_with_scheme(self): scheme = Scheme(options=[Option(value="Cat", expression="Meow")]) question = MultipleChoiceQuestion( "What?", choices=["Hello", "World"], options=[Option(value="Hello", expression="World")], scheme=scheme, ) self.assertEqual( [ Option(value="a", expression="Hello"), Option(value="b", expression="World"), Option(value="Hello", expression="World"), Option(value="Cat", expression="Meow"), ], question.get_options(), ) self.assertEqual( [ Option(value="Hello", expression="World"), Option(value="Cat", expression="Meow"), ], question.primitive_options, ) # External update new_scheme = Scheme(options=[Option(value="Dog", expression="Bark")]) question.update_scheme(new_scheme) self.assertEqual( [ Option(value="Hello", expression="World"), Option(value="Cat", expression="Meow"), Option(value="Dog", expression="Bark"), ], question.primitive_options, ) self.assertEqual( [ Option(value="a", expression="Hello"), Option(value="b", expression="World"), Option(value="Hello", expression="World"), Option(value="Cat", expression="Meow"), Option(value="Dog", expression="Bark"), ], question.get_options(), )
def _test_style(self, style, sample): question = MultipleChoiceQuestion( "What?", style=style, choices=["???" for _ in range(len(sample))] ) for option, value in zip(question.get_options(), sample): self.assertEqual(value, option.value)
def test_choices_converted_to_options(self): choices = ["Hello", "World"] question = MultipleChoiceQuestion("What?", choices=choices) self.assertEqual(len(choices), len(question.options)) for option, expression in zip(question.get_options(), choices): self.assertEqual(expression, option.expression)
def test_choices_combined_with_options(self): question = MultipleChoiceQuestion( "What?", choices=["Hello", "World"], options=[Option(value="Hello", expression="World")], ) self.assertEqual( [ Option(value="a", expression="Hello"), Option(value="b", expression="World"), Option(value="Hello", expression="World"), ], question.get_options(), )