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
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 = [ installer.PageInfo( None, [installer.InstallerOption(installer_mock, 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_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
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