コード例 #1
0
    def test_choices_choose_default(self):
        """Choices with a default without any answer return callback"""
        callback1 = Mock()
        choices = [Choice(0, "Choice0", Mock()), Choice(1, "Choice1", callback1, is_default=True),
                   Choice(2, "Choice2", Mock())]
        inter = TextWithChoices("Foo Content", choices)

        self.assertEquals(inter.choose(), callback1.return_value)
コード例 #2
0
    def test_choices_choose_with_shorcut_no_right_casse(self):
        """Choose with shortcut without respecting the casse"""
        callback1 = Mock()
        choices = [Choice(0, "Choice0", Mock(), txt_shorcut="A"), Choice(1, "Choice1", callback1, txt_shorcut="B"),
                   Choice(2, "Choice2", Mock())]
        inter = TextWithChoices("Foo Content", choices)

        self.assertEquals(inter.choose(answer='b'), callback1.return_value)
コード例 #3
0
    def test_choices_choose_with_label_no_right_casse(self):
        """Choose with label without respecting the casse"""
        callback1 = Mock()
        choices = [Choice(0, "Choice0", Mock()), Choice(1, "Choice1", callback1),
                   Choice(2, "Choice2", Mock())]
        inter = TextWithChoices("Foo Content", choices)

        self.assertEquals(inter.choose(answer='chOIce1'), callback1.return_value)
コード例 #4
0
    def test_choices_choose_with_partial_shorcut_run_right_callback(self):
        """Choose with some having text shortcut calls the correct callback"""
        callback1 = Mock()
        choices = [Choice(0, "Choice0", Mock()), Choice(1, "Choice1", callback1, txt_shorcut="B"),
                   Choice(2, "Choice2", Mock())]
        inter = TextWithChoices("Foo Content", choices)

        self.assertEquals(inter.choose(answer='B'), callback1.return_value)
コード例 #5
0
    def test_choices_choose_with_label_run_right_callback(self):
        """Choose with label calls the correct callback"""
        callback1 = Mock()
        callback2 = Mock()
        choices = [Choice(0, "Choice0", Mock(), txt_shorcut="A"), Choice(1, "Choice1", callback1, txt_shorcut="B"),
                   Choice(2, "Choice2", callback2, txt_shorcut="C")]
        inter = TextWithChoices("Foo Content", choices)

        self.assertEquals(inter.choose(answer='Choice1'), callback1.return_value)
        self.assertEquals(inter.choose(answer='Choice2'), callback2.return_value)
コード例 #6
0
    def test_choices_choose_run_right_callback(self):
        """Choose call the correct callback"""
        callback1 = Mock()
        callback2 = Mock()
        choices = [Choice(0, "Choice0", Mock()), Choice(1, "Choice1", callback1),
                   Choice(2, "Choice2", callback2)]
        inter = TextWithChoices("Foo Content", choices)

        self.assertEquals(inter.choose(choice_id=1), callback1.return_value)
        self.assertEquals(inter.choose(choice_id=2), callback2.return_value)
コード例 #7
0
    def test_choices_choose_with_shorcut_no_right_casse(self):
        """Choose with shortcut without respecting the casse"""
        callback1 = Mock()
        choices = [
            Choice(0, "Choice0", Mock(), txt_shorcut="A"),
            Choice(1, "Choice1", callback1, txt_shorcut="B"),
            Choice(2, "Choice2", Mock())
        ]
        inter = TextWithChoices("Foo Content", choices)

        self.assertEquals(inter.choose(answer='b'), callback1.return_value)
コード例 #8
0
    def test_choices_choose_default(self):
        """Choices with a default without any answer return callback"""
        callback1 = Mock()
        choices = [
            Choice(0, "Choice0", Mock()),
            Choice(1, "Choice1", callback1, is_default=True),
            Choice(2, "Choice2", Mock())
        ]
        inter = TextWithChoices("Foo Content", choices)

        self.assertEquals(inter.choose(), callback1.return_value)
コード例 #9
0
    def test_choices_choose_with_partial_shorcut_run_right_callback(self):
        """Choose with some having text shortcut calls the correct callback"""
        callback1 = Mock()
        choices = [
            Choice(0, "Choice0", Mock()),
            Choice(1, "Choice1", callback1, txt_shorcut="B"),
            Choice(2, "Choice2", Mock())
        ]
        inter = TextWithChoices("Foo Content", choices)

        self.assertEquals(inter.choose(answer='B'), callback1.return_value)
コード例 #10
0
    def test_choices_choose_with_label_no_right_casse(self):
        """Choose with label without respecting the casse"""
        callback1 = Mock()
        choices = [
            Choice(0, "Choice0", Mock()),
            Choice(1, "Choice1", callback1),
            Choice(2, "Choice2", Mock())
        ]
        inter = TextWithChoices("Foo Content", choices)

        self.assertEquals(inter.choose(answer='chOIce1'),
                          callback1.return_value)
コード例 #11
0
    def test_choices_choose_run_right_callback(self):
        """Choose call the correct callback"""
        callback1 = Mock()
        callback2 = Mock()
        choices = [
            Choice(0, "Choice0", Mock()),
            Choice(1, "Choice1", callback1),
            Choice(2, "Choice2", callback2)
        ]
        inter = TextWithChoices("Foo Content", choices)

        self.assertEquals(inter.choose(choice_id=1), callback1.return_value)
        self.assertEquals(inter.choose(choice_id=2), callback2.return_value)
コード例 #12
0
    def test_choices_choose_with_label_run_right_callback(self):
        """Choose with label calls the correct callback"""
        callback1 = Mock()
        callback2 = Mock()
        choices = [
            Choice(0, "Choice0", Mock(), txt_shorcut="A"),
            Choice(1, "Choice1", callback1, txt_shorcut="B"),
            Choice(2, "Choice2", callback2, txt_shorcut="C")
        ]
        inter = TextWithChoices("Foo Content", choices)

        self.assertEquals(inter.choose(answer='Choice1'),
                          callback1.return_value)
        self.assertEquals(inter.choose(answer='Choice2'),
                          callback2.return_value)
コード例 #13
0
    def get_metadata_and_check_license(self, result):
        """Diverge from the baseinstaller implementation in order to allow language selection"""

        logger.debug("Parse download metadata")
        error_msg = result[self.download_page].error
        if error_msg:
            logger.error("An error occurred while downloading {}: {}".format(
                self.download_page, error_msg))
            UI.return_main_screen(status_code=1)

        arch = platform.machine()
        arg_lang_url = None
        default_label = ''
        tag_machine = ''
        if arch == 'x86_64':
            tag_machine = '64'

        reg_expression = r'href="(\S+os=linux{}&lang=\S+)"'.format(
            tag_machine)
        languages = []
        decoded_page = result[self.download_page].buffer.getvalue().decode()
        for index, p in enumerate(re.finditer(reg_expression, decoded_page)):
            with suppress(AttributeError):
                url = p.group(1)

            m = re.search(r'lang=(.*)', url)
            with suppress(AttributeError):
                lang = m.group(1)

            if self.arg_lang and self.arg_lang.lower() == lang.lower():
                arg_lang_url = url
                break
            else:
                is_default_choice = False
                if lang == "en-US":
                    default_label = "(default: en-US)"
                    is_default_choice = True
                choice = Choice(index,
                                lang,
                                partial(self.language_select_callback, url),
                                is_default=is_default_choice)
                languages.append(choice)

        if self.arg_lang:
            logger.debug("Selecting {} lang".format(self.arg_lang))
            if not arg_lang_url:
                logger.error(
                    "Could not find a download url for language {}".format(
                        self.arg_lang))
                UI.return_main_screen(status_code=1)
            self.language_select_callback(arg_lang_url)
        else:
            if not languages:
                logger.error(
                    "Download page changed its syntax or is not parsable")
                UI.return_main_screen(status_code=1)
            logger.debug("Check list of installable languages.")
            UI.delayed_display(
                TextWithChoices(_("Choose language: {}".format(default_label)),
                                languages, True))
コード例 #14
0
    def test_choices_wrong_label_raise(self):
        """Wrong label answer raises an exception"""
        choices = [
            Choice(0, "Choice0", Mock()),
            Choice(1, "Choice1", Mock()),
            Choice(2, "Choice2", Mock())
        ]
        inter = TextWithChoices("Foo Content", choices)

        self.assertRaises(InputError, inter.choose, answer='abc')
コード例 #15
0
    def test_choices_choose_no_default_raises(self):
        """We raise an exception if there is no default and we choose without any answer"""
        choices = [
            Choice(0, "Choice0", Mock()),
            Choice(1, "Choice1", Mock()),
            Choice(2, "Choice2", Mock())
        ]
        inter = TextWithChoices("Foo Content", choices)

        self.assertRaises(InputError, inter.choose)
コード例 #16
0
    def test_choices_wrong_txt_shortcut_raise(self):
        """Wrong txt shortcut raises an exception"""
        choices = [
            Choice(0, "Choice0", Mock(), txt_shorcut='A'),
            Choice(1, "Choice1", Mock(), txt_shorcut='B'),
            Choice(2, "Choice2", Mock(), txt_shorcut='C')
        ]
        inter = TextWithChoices("Foo Content", choices)

        self.assertRaises(InputError, inter.choose, answer='Z')
コード例 #17
0
    def test_choices_with_default(self):
        """We can instantiate choices interactions with a default"""
        choices = [
            Choice(0, "Choice0", lambda: ""),
            Choice(1, "Choice1", lambda: "", is_default=True),
            Choice(2, "Choice2", lambda: "")
        ]
        inter = TextWithChoices("Foo Content", choices)

        self.assertEquals(inter.choices, choices)
        self.assertEquals(inter.content, "Foo Content")
コード例 #18
0
    def test_choices_with_text_shorcut(self):
        """We can instantiate choices interactions with shortcut"""
        choices = [
            Choice(0, "Choice0", lambda: "", txt_shorcut="A"),
            Choice(1, "Choice1", lambda: "", txt_shorcut="B"),
            Choice(2, "Choice2", lambda: "", txt_shorcut="C")
        ]
        inter = TextWithChoices("Foo Content", choices)

        self.assertEquals(inter.choices, choices)
        self.assertEquals(inter.content, "Foo Content")
コード例 #19
0
    def test_choices(self):
        """We can instantiate with a choices interactions"""
        choices = [
            Choice(0, "Choice0", lambda: ""),
            Choice(1, "Choice1", lambda: ""),
            Choice(2, "Choice2", lambda: "")
        ]
        inter = TextWithChoices("Foo Content", choices)

        self.assertEquals(inter.choices, choices)
        self.assertEquals(inter.content, "Foo Content")
コード例 #20
0
    def test_choices_prompt(self):
        """We give a prompt for normal choice"""
        choices = [
            Choice(0, "Choice0", lambda: ""),
            Choice(1, "Choice1", lambda: ""),
            Choice(2, "Choice2", lambda: "")
        ]
        inter = TextWithChoices("Foo Content", choices)

        self.assertEquals(inter.prompt,
                          "Foo Content [Choice0/Choice1/Choice2] ")
コード例 #21
0
    def test_choices_prompt_with_partial_txt_shortcut(self):
        """We give a prompt, some choices having txt shortcut"""
        choices = [
            Choice(0, "Choice0", lambda: "", txt_shorcut="A"),
            Choice(1, "Choice1", lambda: ""),
            Choice(2, "Choice2", lambda: "", txt_shorcut="c")
        ]
        inter = TextWithChoices("Foo Content", choices)

        self.assertEquals(inter.prompt,
                          "Foo Content [Choice0 (A)/Choice1/Choice2 (c)] ")
コード例 #22
0
    def test_choices_prompt_with_txt_shortcut(self):
        """We give a prompt with txt shortcut if any"""
        choices = [
            Choice(0, "Choice0", lambda: "", txt_shorcut="A"),
            Choice(1, "Choice1", lambda: "", txt_shorcut="B"),
            Choice(2, "Choice2", lambda: "", txt_shorcut="c")
        ]
        inter = TextWithChoices("Foo Content", choices)

        self.assertEquals(
            inter.prompt, "Foo Content [Choice0 (A)/Choice1 (B)/Choice2 (c)] ")
コード例 #23
0
    def test_choices_wrong_choice_id_raise(self):
        """Wrong choice_id raises an exception"""
        callback1 = Mock()
        callback2 = Mock()
        choices = [
            Choice(0, "Choice0", Mock()),
            Choice(1, "Choice1", callback1),
            Choice(2, "Choice2", callback2)
        ]
        inter = TextWithChoices("Foo Content", choices)

        self.assertRaises(InputError, inter.choose, choice_id=3)
コード例 #24
0
    def test_choices_prompt_with_newline(self):
        """We give a prompt with newline before options if requested"""
        choices = [
            Choice(0, "Choice0", lambda: ""),
            Choice(1, "Choice1", lambda: ""),
            Choice(2, "Choice2", lambda: "")
        ]
        inter = TextWithChoices("Foo Content",
                                choices,
                                newline_before_option=True)

        self.assertEquals(inter.prompt,
                          "Foo Content\n[Choice0/Choice1/Choice2] ")