Exemple #1
0
 def test_flags(self):
     installer_mock = Mock(spec=installer.Installer)
     flags1 = fomod.Flags()
     flags1["flag1"] = "value1"
     flags2 = fomod.Flags()
     flags2["flag2"] = "value2"
     flags3 = fomod.Flags()
     flags3["flag1"] = "value3"
     option1 = fomod.Option()
     option1.flags = flags1
     option2 = fomod.Option()
     option2.flags = flags2
     option3 = fomod.Option()
     option3.flags = flags3
     installer_mock._previous_pages = [
         installer.PageInfo(
             None, [installer.InstallerOption(installer_mock, option1)]),
         installer.PageInfo(
             None,
             [
                 installer.InstallerOption(installer_mock, option2),
                 installer.InstallerOption(installer_mock, option3),
             ],
         ),
     ]
     expected = {"flag1": "value3", "flag2": "value2"}
     assert installer.Installer.flags(installer_mock) == expected
Exemple #2
0
    def test_validate(self):
        expected = warnings.ValidationWarning("Empty Group",
                                              "This group is empty.",
                                              self.group)
        assert expected in self.group.validate()
        expected = warnings.ValidationWarning("Empty Group Name",
                                              "This group has no name.",
                                              self.group)
        assert expected in self.group.validate()

        self.group.type = fomod.GroupType.ATLEASTONE
        expected = warnings.ValidationWarning(
            "Not Enough Selectable Options",
            "This group needs at least one selectable "
            "option but none are available.",
            self.group,
            critical=True,
        )
        assert expected in self.group.validate()

        self.group.type = fomod.GroupType.EXACTLYONE
        expected = warnings.ValidationWarning(
            "Not Enough Selectable Options",
            "This group needs exactly one selectable "
            "option but none are available.",
            self.group,
            critical=True,
        )
        assert expected in self.group.validate()

        option1 = fomod.Option()
        option1.type = fomod.OptionType.REQUIRED
        self.group.append(option1)
        option2 = fomod.Option()
        option2.type = fomod.OptionType.REQUIRED
        self.group.append(option2)

        self.group.type = fomod.GroupType.ATMOSTONE
        expected = warnings.ValidationWarning(
            "Too Many Required Options",
            "This group can have one option selected "
            "at most but at least two are required.",
            self.group,
            critical=True,
        )
        assert expected in self.group.validate()

        self.group.type = fomod.GroupType.EXACTLYONE
        expected = warnings.ValidationWarning(
            "Too Many Required Options",
            "This group can only have exactly one "
            "option selected but at least two are required.",
            self.group,
            critical=True,
        )
        assert expected in self.group.validate()
 def test_files(self):
     installer_mock = Mock(spec=installer.Installer)
     installer_mock.path = None
     files1 = fomod.Files()
     file1 = fomod.File("file", attrib={"priority": "2"})
     file1.src = "source1"
     file1.dst = "dest1"
     files1._file_list = [file1]
     installer_mock.root = Mock(spec=fomod.Root)
     installer_mock.root.files = files1
     files2 = fomod.Files()
     file2 = fomod.File("file", attrib={"priority": "0"})
     file2.src = "source2"
     file2.dst = "dest1"
     file3 = fomod.File("file", attrib={"priority": "0"})
     file3.src = "source3"
     file3.dst = "dest2"
     files2._file_list = [file2, file3]
     option2 = fomod.Option()
     option2.files = files2
     installer_mock._previous_pages = OrderedDict([(None, [option2])])
     files3 = fomod.Files()
     file4 = fomod.File("file", attrib={"priority": "1"})
     file4.src = "source4"
     file4.dst = "dest3"
     files3._file_list = [file4]
     installer_mock.root.file_patterns = {fomod.Conditions(): files3}
     expected = {"source1": "dest1", "source3": "dest2", "source4": "dest3"}
     assert installer.Installer.files(installer_mock) == expected
 def test_flags(self):
     installer_mock = Mock(spec=installer.Installer)
     flags1 = fomod.Flags()
     flags1["flag1"] = "value1"
     flags2 = fomod.Flags()
     flags2["flag2"] = "value2"
     flags3 = fomod.Flags()
     flags3["flag1"] = "value3"
     option1 = fomod.Option()
     option1.flags = flags1
     option2 = fomod.Option()
     option2.flags = flags2
     option3 = fomod.Option()
     option3.flags = flags3
     installer_mock._previous_pages = OrderedDict([(None, [option1]),
                                                   (None,
                                                    [option2, option3])])
     expected = {"flag1": "value3", "flag2": "value2"}
     assert installer.Installer.flags(installer_mock) == expected
 def test_next(self):
     test_root = fomod.Root()
     test_installer = installer.Installer(test_root)
     assert test_installer.next() is None
     test_root.pages.append(fomod.Page())
     test_group = fomod.Group()
     test_group.append(fomod.Option())
     test_group[0].flags["flag"] = "value"
     test_group.append(fomod.Option())
     test_root.pages[0].append(test_group)
     assert test_installer.next()._object is test_root.pages[0]
     test_group.type = fomod.GroupType.ALL
     with pytest.raises(installer.InvalidSelection):
         test_installer.next()
     test_group.type = fomod.GroupType.ATLEASTONE
     with pytest.raises(installer.InvalidSelection):
         test_installer.next()
     test_group.type = fomod.GroupType.EXACTLYONE
     with pytest.raises(installer.InvalidSelection):
         test_installer.next()
     test_group.type = fomod.GroupType.ATMOSTONE
     with pytest.raises(installer.InvalidSelection):
         test_installer.next([
             installer.InstallerOption(test_installer, test_group[0]),
             installer.InstallerOption(test_installer, test_group[1]),
         ])
     test_group[0].type = fomod.OptionType.REQUIRED
     with pytest.raises(installer.InvalidSelection):
         test_installer.next()
     test_group[0].type = fomod.OptionType.NOTUSABLE
     with pytest.raises(installer.InvalidSelection):
         test_installer.next(
             [installer.InstallerOption(test_installer, test_group[0])])
     test_root.pages.append(fomod.Page())
     test_root.pages[1].conditions["flag"] = "other"
     test_root.pages.append(fomod.Page())
     assert test_installer.next()._object is test_root.pages[2]
     assert test_installer.next() is None
Exemple #6
0
    def test_to_string(self):
        option1 = fomod.Option()
        option1_text = option1.to_string()
        self.group.append(option1)
        self.group.name = "name"
        self.group.order = fomod.Order.DESCENDING
        self.group.type = fomod.GroupType.ALL
        expected = textwrap.dedent("""\
                <group name="name" type="SelectAll">
                  <plugins order="Descending">
{}
                  </plugins>
                </group>""".format(textwrap.indent(option1_text, "    " * 5)))
        assert self.group.to_string() == expected
Exemple #7
0
    def test_to_string(self):
        group1 = fomod.Group()
        group1.append(fomod.Option())
        text = group1.to_string()
        group2 = fomod.Group()
        self.page.extend([group1, group2])
        self.page.name = "boop"
        self.page.order = fomod.Order.ASCENDING
        expected = textwrap.dedent("""\
                <installStep name="boop">
                  <optionalFileGroups order="Ascending">
{}
                  </optionalFileGroups>
                </installStep>""".format(textwrap.indent(text, "    " * 5)))
        assert self.page.to_string() == expected
 def test_previous(self):
     installer_mock = Mock(spec=installer.Installer)
     test_page = fomod.Page()
     test_option = fomod.Option()
     installer_mock._has_finished = True
     installer_mock._previous_pages = OrderedDict([(test_page,
                                                    [test_option])])
     installer_mock._current_page = None
     result = installer.Installer.previous(installer_mock)
     assert result[0]._object is test_page
     assert result[1] == [test_option]
     assert not installer_mock._has_finished
     assert not installer_mock._previous_pages
     assert installer_mock._current_page is test_page
     installer_mock._previous_pages = OrderedDict()
     assert installer.Installer.previous(installer_mock) is None
     assert installer_mock._current_page is None
def test_installeroption():
    test_option = fomod.Option()
    test_option.name = "name"
    test_option.description = "description"
    test_option.image = "image"
    test_option.type = fomod.OptionType.REQUIRED
    inst_option = installer.InstallerOption(None, test_option)
    assert inst_option._object is test_option
    assert inst_option._installer is None
    assert inst_option.name == "name"
    assert inst_option.description == "description"
    assert inst_option.image == "image"
    assert inst_option.type is fomod.OptionType.REQUIRED
    test_option.type = fomod.Type()
    test_option.type.default = fomod.OptionType.NOTUSABLE
    installer_mock = Mock(spec=installer.Installer)
    inst_option = installer.InstallerOption(installer_mock, test_option)
    assert inst_option._installer is installer_mock
    assert inst_option.type is fomod.OptionType.NOTUSABLE
    test_option.type[fomod.Conditions()] = fomod.OptionType.COULDBEUSABLE
    inst_option = installer.InstallerOption(installer_mock, test_option)
    assert inst_option.type is fomod.OptionType.COULDBEUSABLE
Exemple #10
0
 def setup_method(self):
     self.option = fomod.Option()