Example #1
0
    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)
Example #2
0
    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(),
        )
Example #3
0
    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)
Example #4
0
    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)
Example #5
0
    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(),
        )