def test_getString_quotes(self):
     """
     String values may be quoted.
     """
     config_file = StringIO(
         u'[section]\n'
         u'no_quote: \'maca" \n'
         u'single_quote: \'maca\' \n'
         u'double_quote: "maca" \n'
         u'multiple_single_quote: \'\'maca\'\' \n'
         u'multiple_double_quote: ""maca"" \n'
         u'',
         )
     config = FileConfigurationProxy(
         configuration_file=config_file)
     config.load()
     self.assertEqual(
         u'\'maca"',
         config.getString(u'section', u'no_quote'))
     self.assertEqual(
         u'maca',
         config.getString(u'section', u'single_quote'))
     self.assertEqual(
         u'maca',
         config.getString(u'section', u'double_quote'))
     self.assertEqual(
         u'\'maca\'',
         config.getString(u'section', u'multiple_single_quote'))
     self.assertEqual(
         u'"maca"',
         config.getString(u'section', u'multiple_double_quote'))
 def test_load_unicode_file(self):
     """
     System test for loading unicode data.
     """
     config_content = (
         u'[another_muță]\n'
         u'another_muță_option: another_muță_value\n'
         u'[some_section]\n'
         u'some_section_option: some_section_value\n'
         u'')
     test_filesystem = manufacture.fs
     test_segments = None
     try:
         test_segments = test_filesystem.createFileInTemp(
             content=config_content)
         config_path = test_filesystem.getRealPathFromSegments(
             test_segments)
         with test_filesystem._impersonateUser():
             config = FileConfigurationProxy(
                 configuration_path=config_path)
             config.load()
             sections = config.sections
             self.assertEqual(2, len(sections))
             self.assertTrue(isinstance(sections[0], unicode))
             self.assertTrue(u'another_muță' in sections)
             self.assertTrue(u'some_section' in sections)
             self.assertEqual(
                 u'another_muță_value',
                 config.getString(
                     u'another_muță',
                     u'another_muță_option'))
     finally:
         if test_segments:
             test_filesystem.deleteFile(test_segments, ignore_errors=True)
 def test_getString(self):
     """
     Check getString.
     """
     config_file = StringIO(
         u'[some_section]\n'
         u'some_value:  maca   \n'
         u'[another_muță]\n'
         u'some_value: raca\n'
         u'',
         )
     config = FileConfigurationProxy(
         configuration_file=config_file)
     config.load()
     self.assertEqual(
         u'maca',
         config.getString(u'some_section', u'some_value'))
     self.assertEqual(
         u'raca',
         config.getString(u'another_muță', u'some_value'))
 def test_save(self):
     """
     System test for persisting changes into a file.
     """
     config_content = (
         u'[another_muță]\n'
         u'another_muță_option: another_muță_value\n\n')
     test_filesystem = manufacture.fs
     test_segments = None
     try:
         test_segments = test_filesystem.createFileInTemp(
             content=config_content)
         config_path = test_filesystem.getRealPathFromSegments(
             test_segments)
         with test_filesystem._impersonateUser():
             config = FileConfigurationProxy(
                 configuration_path=config_path)
             config.load()
             self.assertEqual(
                 u'another_muță_value',
                 config.getString(
                     u'another_muță',
                     u'another_muță_option'))
             config.setString(
                     u'another_muță',
                     u'another_muță_option',
                     u'muță_value',
                     )
             config.save()
             config = FileConfigurationProxy(
                 configuration_path=config_path)
             config.load()
             self.assertEqual(
                 u'muță_value',
                 config.getString(
                     u'another_muță',
                     u'another_muță_option'))
     finally:
         if test_segments:
             test_filesystem.deleteFile(test_segments, ignore_errors=True)
 def test_getString_with_wild_charactes(self):
     """
     A string configuration can hold any character and it does not
     require any special escaping.
     """
     config_file = StringIO((
         u'[section]\n'
         u'value: %s\n'
         u'') % (self.special_characters)
         )
     config = FileConfigurationProxy(
         configuration_file=config_file)
     config.load()
     self.assertEqual(
         self.special_characters,
         config.getString(u'section', u'value'))
 def test_getString_with_python_formating(self):
     """
     A string configuration can hold a python string formating
     expressions.
     """
     config_file = StringIO(
         u'[section]\n'
         u'value: do %(some)s value\n'
         u'',
         )
     config = FileConfigurationProxy(
         configuration_file=config_file)
     config.load()
     self.assertEqual(
         u'do %(some)s value',
         config.getString(u'section', u'value'))
    def test_setString_with_wild_charactes(self):
        """
        A string configuration can be set to text containing any characters.
        """
        config_file = StringIO(
            u'[section]\n'
            u'value: value\n'
            u'',
            )
        config = FileConfigurationProxy(
            configuration_file=config_file)
        config.load()

        config.setString(u'section', u'value', self.special_characters)

        self.assertEqual(
            self.special_characters,
            config.getString(u'section', u'value'))