当前位置: 首页>>代码示例>>Python>>正文


Python Settings.set_config_attributes方法代码示例

本文整理汇总了Python中settings.Settings.set_config_attributes方法的典型用法代码示例。如果您正苦于以下问题:Python Settings.set_config_attributes方法的具体用法?Python Settings.set_config_attributes怎么用?Python Settings.set_config_attributes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在settings.Settings的用法示例。


在下文中一共展示了Settings.set_config_attributes方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_set_config_should_update_value_for_level_easy_to_max_35

# 需要导入模块: from settings import Settings [as 别名]
# 或者: from settings.Settings import set_config_attributes [as 别名]
 def test_set_config_should_update_value_for_level_easy_to_max_35(self):
     setting_node = "Level"
     setting_name = "Easy"
     attribute_name = "max"
     new_attribute_value = "35"
     settings_xml = Settings()
     settings_xml.read_settings_from_file()
     settings_xml.set_config_attributes(setting_node, setting_name, attribute_name, new_attribute_value)
     settings_xml.write_settings()
     settings_xml.read_settings_from_file()
     result = settings_xml.get_attribute_value_for_setting(setting_node, setting_name, attribute_name)
     self.assertEqual(new_attribute_value, result)
开发者ID:rsanchezG,项目名称:sudokuB-1,代码行数:14,代码来源:test_settings.py

示例2: test_display_modify_setting_should_display_current_settings

# 需要导入模块: from settings import Settings [as 别名]
# 或者: from settings.Settings import set_config_attributes [as 别名]
 def test_display_modify_setting_should_display_current_settings(self):
     sudoku_menu = Menu()
     sudoku_setting = Settings()
     sudoku_setting.set_config_attributes("Level", "Easy","max", 35)
     sudoku_setting.set_config_attributes("Level", "Easy","min", 30)
     sudoku_setting.set_config_attributes("Level", "Medium","max", 50)
     sudoku_setting.set_config_attributes("Level", "Medium","min", 40)
     sudoku_setting.set_config_attributes("Level", "Hard","max", 70)
     sudoku_setting.set_config_attributes("Level", "Hard","min", 60)
     expected_string = "========================\n" + \
                       "\tAlgorithm:\n" + \
                       "\t\t-Peter Norvig (Default)\n" + \
                       "\t\t-Backtracking\n" + \
                       "\t\t-Brute Force\n" + \
                       "\tLevel:\n" + \
                       "\t\t-Easy\n" + \
                       "\t\t\tmax = 35\n" + \
                       "\t\t\tmin = 30\n" + \
                       "\t\t-Medium\n" + \
                       "\t\t\tmax = 50\n" + \
                       "\t\t\tmin = 40\n" + \
                       "\t\t-Hard (Default)\n" + \
                       "\t\t\tmax = 70\n" + \
                       "\t\t\tmin = 60\n" + \
                       "\tInput:\n" + \
                       "\t\t-Console\n" + \
                       "\t\t\tpath = \n" + \
                       "\t\t-TXT\n" + \
                       "\t\t\tpath = ../custom_games\n" + \
                       "\t\t-CSV (Default)\n" + \
                       "\t\t\tpath = ../custom_games\n" + \
                       "\tOutput:\n" + \
                       "\t\t-TXT (Default)\n" + \
                       "\t\t\tpath = ../game_results\n" + \
                       "========================="
     sudoku_menu.display_settings()
     self.assertEqual(expected_string, sudoku_menu.menu_string)
开发者ID:Henry-Benito,项目名称:sudokuB,代码行数:39,代码来源:test_menu.py

示例3: __init__

# 需要导入模块: from settings import Settings [as 别名]
# 或者: from settings.Settings import set_config_attributes [as 别名]

#.........这里部分代码省略.........
        list_of_settings = []
        good_input_values = ""
        counter_index = 1

        for element in elements:
            print str(counter_index)+". " + element.attrib["name"]
            list_of_settings.append(element.attrib["name"])
            good_input_values += "|"+str(counter_index)
            counter_index += 1

        print "m. Go to main menu"
        print "x. Exit"
        self.get_option_value_from_user()

        if self.is_a_valid_option_from_settings(good_input_values) is True:
            self.sudoku_settings.set_config(setting, list_of_settings[int(self.user_option) - 1])
            self.sudoku_settings.write_settings()
        self.status = "m"

    def is_a_valid_option_from_settings(self, good_input_values):
        """Validate a user input value against values that have read from settings
        Keyword arguments:
        good_input_values -- list of different values have read from settings.
        """
        print good_input_values
        patron_input_values = "^(" + self.exit_game_option + "|" + self.go_main_menu_option + \
                              good_input_values + "){1}$"
        print patron_input_values
        if re.match(good_input_values, self.user_option):
            print self.user_option
            if self.user_option == self.exit_game_option or \
               self.user_option == self.go_main_menu_option:
                return False
            return True
        else:
            return False

    def display_select_setting_name_to_modify_attributes(self, setting_to_modify):
        """Display names of setting to modify his attributes

        Keyword arguments:
        setting_to_modify -- setting used to get a list of different values
        """
        setting = setting_to_modify
        print "\n\nSet attributes for " + setting + ":"
        elements = self.sudoku_settings.get_setting_list_to(setting)
        list_of_settings = []
        counter_index = 1

        for element in elements:
            print str(counter_index)+". " + element.attrib["name"]
            list_of_settings.append(element.attrib["name"])
            counter_index += 1
        print "m. Go to main menu"
        print "x. Exit"

        setting_value = str(raw_input("Please enter a value:"))

        if setting_value == "x":
            self.status = "exit"
        elif setting_value == "m":
            pass
        elif int(setting_value) >= 1 and int(setting_value) <= len(list_of_settings):
            self.__set_attributes_for_setting(setting, list_of_settings[int(setting_value) - 1])
        else:
            pass

    def __set_attributes_for_setting(self, setting, setting_name):
        """Display list of attributes to be modified

        Keyword arguments:
        setting -- name of current setting i.e. Algorithm
        setting_name -- name of setting value i.e. Peter Norvig
        """
        print "\n\nAttributes for " + setting_name + ":"
        elements = self.sudoku_settings.get_setting_list_to(setting)

        for i in range(len(elements)):
            if elements[i].attrib["name"] == setting_name:
                element_index = i
        for attribute in elements[element_index].attrib.keys():
            if attribute != "name" and attribute != "default":
                new_value = str(raw_input("Please enter a new value for " + attribute + ":"))
                self.sudoku_settings.set_config_attributes(setting, setting_name, attribute,
                                                           new_value)
                self.sudoku_settings.write_settings()
        self.status = "m"
        print "Settings changed successfully.\nReturning to main menu..."

    def exit(self):
        """
        Update status value in order to exit the game.
        """
        self.status = self.exit_game_option

    def go_to_main_menu(self):
        """
        Update status value in order to go to main menu
        """
        self.status = self.go_main_menu_option
开发者ID:rsanchezG,项目名称:sudokuB-1,代码行数:104,代码来源:menu.py


注:本文中的settings.Settings.set_config_attributes方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。