Ejemplo n.º 1
0
 def test_empty_lines_preserved_after_multiple_edits(self):
     ini.set_option(self.tfile.name, {
         'SectionB': {
             'test3': 'this value will be edited two times'
         },
     })
     self.test_empty_lines_preserved_after_edit()
Ejemplo n.º 2
0
    def test_empty_lines_preserved_after_edit(self):
        ini.set_option(self.tfile.name, {
            'SectionB': {'test3': 'new value 3B'},
        })
        with salt.utils.fopen(self.tfile.name, 'r') as fp:
            file_content = fp.read()
        self.assertEqual('''\
# Comment on the first line

# First main option
option1=main1

# Second main option
option2=main2


[main]
# Another comment
test1=value 1

test2=value 2

[SectionB]
test1=value 1B

# Blank line should be above
test3=new value 3B

[SectionC]
# The following option is empty
empty_option=

''', file_content)
Ejemplo n.º 3
0
    def test_empty_lines_preserved_after_edit(self):
        ini.set_option(self.tfile.name, {
            'SectionB': {'test3': 'new value 3B'},
        })
        with salt.utils.fopen(self.tfile.name, 'rb') as fp:
            file_content = fp.read()
        self.assertEqual('''\
# Comment on the first line

# First main option
option1=main1

# Second main option
option2=main2


[main]
# Another comment
test1=value 1

test2=value 2

[SectionB]
test1=value 1B

# Blank line should be above
test3=new value 3B

[SectionC]
# The following option is empty
empty_option=

''', file_content)
Ejemplo n.º 4
0
 def test_empty_lines_preserved_after_edit(self):
     ini.set_option(self.tfile.name, {
         'SectionB': {'test3': 'new value 3B'},
     })
     expected = os.linesep.join([
         '# Comment on the first line',
         '',
         '# First main option',
         'option1 = main1',
         '',
         '# Second main option',
         'option2 = main2',
         '',
         '[main]',
         '# Another comment',
         'test1 = value 1',
         '',
         'test2 = value 2',
         '',
         '[SectionB]',
         'test1 = value 1B',
         '',
         '# Blank line should be above',
         'test3 = new value 3B',
         '',
         '[SectionC]',
         '# The following option is empty',
         'empty_option = ',
         ''
     ])
     with salt.utils.files.fopen(self.tfile.name, 'r') as fp:
         file_content = fp.read()
     self.assertEqual(expected, file_content)
Ejemplo n.º 5
0
 def test_empty_value_preserved_after_edit(self):
     ini.set_option(self.tfile.name, {
         'SectionB': {'test3': 'new value 3B'},
     })
     with salt.utils.fopen(self.tfile.name, 'rb') as fp:
         file_content = fp.read()
     self.assertIn('\nempty_option=\n', file_content,
                   'empty_option was not preserved')
Ejemplo n.º 6
0
 def test_empty_value_preserved_after_edit(self):
     ini.set_option(self.tfile.name, {
         'SectionB': {'test3': 'new value 3B'},
     })
     with salt.utils.fopen(self.tfile.name, 'r') as fp:
         file_content = fp.read()
     self.assertIn('\nempty_option=\n', file_content,
                   'empty_option was not preserved')
Ejemplo n.º 7
0
 def test_empty_lines_multiple_edits(self):
     '''
     Test empty lines preserved after multiple edits
     '''
     ini.set_option(self.tfile.name, {
         'SectionB': {'test3': 'this value will be edited two times'},
     })
     self.test_empty_lines()
Ejemplo n.º 8
0
 def test_empty_value_preserved_after_edit(self):
     ini.set_option(self.tfile.name, {
         'SectionB': {'test3': 'new value 3B'},
     })
     with salt.utils.files.fopen(self.tfile.name, 'r') as fp:
         file_content = fp.read()
     expected = '{0}{1}{0}'.format(os.linesep, 'empty_option = ')
     self.assertIn(expected, file_content, 'empty_option was not preserved')
Ejemplo n.º 9
0
 def test_empty_lines_multiple_edits(self):
     """
     Test empty lines preserved after multiple edits
     """
     ini.set_option(
         self.tfile.name,
         {"SectionB": {"test3": "this value will be edited two times"}},
     )
     self.test_empty_lines()
Ejemplo n.º 10
0
 def test_empty_value(self):
     """
     Test empty value preserved after edit
     """
     ini.set_option(self.tfile.name, {"SectionB": {"test3": "new value 3B"}})
     with salt.utils.files.fopen(self.tfile.name, "r") as fp_:
         file_content = salt.utils.stringutils.to_unicode(fp_.read())
     expected = "{0}{1}{0}".format(os.linesep, "empty_option = ")
     self.assertIn(expected, file_content, "empty_option was not preserved")
Ejemplo n.º 11
0
 def test_empty_value(self):
     '''
     Test empty value preserved after edit
     '''
     ini.set_option(self.tfile.name, {
         'SectionB': {'test3': 'new value 3B'},
     })
     with salt.utils.files.fopen(self.tfile.name, 'r') as fp_:
         file_content = salt.utils.stringutils.to_unicode(fp_.read())
     expected = '{0}{1}{0}'.format(os.linesep, 'empty_option = ')
     self.assertIn(expected, file_content, 'empty_option was not preserved')
Ejemplo n.º 12
0
 def test_set_option(self):
     result = ini.set_option(self.tfile.name, {
         'SectionB': {
             'test3': 'new value 3B',
             'test_set_option': 'test_set_value'
         },
         'SectionD': {
             'test_set_option2': 'test_set_value1'
         }
     })
     self.assertEqual(result['changes'], {
         'SectionB': {'test3': {'after': 'new value 3B',
                                'before': 'value 3B'},
                      'test_set_option': {'after': 'test_set_value',
                                          'before': None}
         },
         'SectionD': {'test_set_option2': {'after': 'test_set_value1',
                                           'before': None}
         }
     })
     # Check existing option updated
     self.assertEqual(
         ini.get_option(self.tfile.name, 'SectionB', 'test3'),
         'new value 3B')
     # Check new section and option added
     self.assertEqual(
         ini.get_option(self.tfile.name, 'SectionD', 'test_set_option2'),
         'test_set_value1')
Ejemplo n.º 13
0
 def test_set_option(self):
     result = ini.set_option(self.tfile.name, {
         'SectionB': {
             'test3': 'new value 3B',
             'test_set_option': 'test_set_value'
         },
         'SectionD': {
             'test_set_option2': 'test_set_value1'
         }
     })
     self.assertEqual(result['changes'], {
         'SectionB': {'test3': {'after': 'new value 3B',
                                'before': 'value 3B'},
                      'test_set_option': {'after': 'test_set_value',
                                          'before': None}
         },
         'SectionD': {'test_set_option2': {'after': 'test_set_value1',
                                           'before': None}
         }
     })
     # Check existing option updated
     self.assertEqual(
         ini.get_option(self.tfile.name, 'SectionB', 'test3'),
         'new value 3B')
     # Check new section and option added
     self.assertEqual(
         ini.get_option(self.tfile.name, 'SectionD', 'test_set_option2'),
         'test_set_value1')
Ejemplo n.º 14
0
 def test_empty_lines(self):
     """
     Test empty lines preserved after edit
     """
     ini.set_option(self.tfile.name, {"SectionB": {"test3": "new value 3B"}})
     expected = os.linesep.join(
         [
             "# Comment on the first line",
             "",
             "# First main option",
             "option1 = main1",
             "",
             "# Second main option",
             "option2 = main2",
             "",
             "[main]",
             "# Another comment",
             "test1 = value 1",
             "",
             "test2 = value 2",
             "",
             "[SectionB]",
             "test1 = value 1B",
             "",
             "# Blank line should be above",
             "test3 = new value 3B",
             "",
             "[SectionC]",
             "# The following option is empty",
             "empty_option = ",
             "",
         ]
     )
     with salt.utils.files.fopen(self.tfile.name, "r") as fp_:
         file_content = salt.utils.stringutils.to_unicode(fp_.read())
     self.assertEqual(expected, file_content)
Ejemplo n.º 15
0
 def test_set_option(self):
     """
     Test set_option method.
     """
     result = ini.set_option(
         self.tfile.name,
         {
             "SectionB": {
                 "test3": "new value 3B",
                 "test_set_option": "test_set_value",
             },
             "SectionD": {"test_set_option2": "test_set_value1"},
         },
     )
     self.assertEqual(
         result,
         {
             "SectionB": {
                 "test3": {"after": "new value 3B", "before": "value 3B"},
                 "test_set_option": {"after": "test_set_value", "before": None},
             },
             "SectionD": {
                 "after": {"test_set_option2": "test_set_value1"},
                 "before": None,
             },
         },
     )
     # Check existing option updated
     self.assertEqual(
         ini.get_option(self.tfile.name, "SectionB", "test3"), "new value 3B"
     )
     # Check new section and option added
     self.assertEqual(
         ini.get_option(self.tfile.name, "SectionD", "test_set_option2"),
         "test_set_value1",
     )
Ejemplo n.º 16
0
 def test_empty_lines_preserved_after_multiple_edits(self):
     ini.set_option(self.tfile.name, {
         'SectionB': {'test3': 'this value will be edited two times'},
     })
     self.test_empty_lines_preserved_after_edit()