Пример #1
0
 def test_local_settings(self):
     """
     Test to see if the local settings parsing works.
     """
     config_parser = configparser.SafeConfigParser()
     config_parser.optionxform = str
     config_file = get_test_config("subcluster/local_settings.ini")
     config_parser.read(config_file)
     local_settings = localsettings.LocalSettings(logger= \
                                                      global_logger)
     local_settings.parse_configuration(config_parser)
     attributes = local_settings.get_attributes()
     self.assertTrue(
         'default' not in attributes,
         msg="Attributes set that weren't in the test config file")
     self.assertTrue('Foo' in attributes and attributes['Foo'] == 'value1',
                     msg="Incorrectly named key." \
                         "  Desired name: Foo; only found  %s." %
                         (" ".join(attributes.keys())))
     self.assertTrue(attributes['Foo'] == 'value1',
                     msg="Incorrect value wanted value1, " \
                         "got %s" % attributes['Foo'])
     self.assertTrue('bar' in attributes and attributes['bar'] == 'value2',
                     msg="Incorrectly named key." \
                         "  Desired name: bar; only found  %s." %
                         (" ".join(attributes.keys())))
     self.assertTrue('bar' in attributes and attributes['bar'] == 'value2',
                     msg="Incorrect value wanted value2, " \
                         "got %s" % attributes['bar'])
    def testParsing(self):
        """
        Test install locations parsing
        """

        config_file = get_test_config("localsettings/local_settings1.ini")
        configuration = configparser.SafeConfigParser()
        configuration.optionxform = str
        configuration.read(config_file)

        settings = localsettings.LocalSettings(logger=global_logger)
        try:
            settings.parse_configuration(configuration)
        except Exception as e:
            self.fail("Received exception while parsing configuration: %s" % e)

        attributes = settings.get_attributes()
        self.assertTrue('test1' in attributes, 'Attribute test1 missing')
        self.assertEqual(attributes['test1'], 'Value1',
                         'Wrong value obtained for test1')

        self.assertFalse('missing_key' in attributes,
                         'Non-existent key (missing_key) found')

        self.assertFalse('default_key' in attributes,
                         'Default key recognized as a local attribute')
    def testBogusQuote(self):
        config_file = get_test_config("localsettings/bogusquote.ini")
        configuration = configparser.SafeConfigParser()
        configuration.optionxform = str
        configuration.read(config_file)

        settings = localsettings.LocalSettings(logger=global_logger)
        self.assertRaises(exceptions.SettingError,
                          settings.parse_configuration, configuration)
Пример #4
0
    def testParsing(self):
        """
        Test install locations parsing
        """

        config_file = get_test_config("localsettings/local_settings1.ini")
        configuration = ConfigParser.SafeConfigParser()
        configuration.optionxform = str
        configuration.read(config_file)

        settings = localsettings.LocalSettings(logger=global_logger)
        try:
            settings.parse_configuration(configuration)
        except Exception, e:
            self.fail("Received exception while parsing configuration: %s" % e)