Merge pull request #49242 from dwoz/blockreplace_better_fix

Blockreplace better fix
This commit is contained in:
Mike Place 2018-08-22 09:21:29 -06:00 committed by GitHub
commit d55d484174
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -2647,57 +2647,57 @@ class FileTest(ModuleCase, SaltReturnAssertsMixin):
class BlockreplaceTest(ModuleCase, SaltReturnAssertsMixin):
marker_start = '# start'
marker_end = '# end'
content = textwrap.dedent('''\
Line 1 of block
Line 2 of block
''')
without_block = textwrap.dedent('''\
Hello world!
# comment here
''')
with_non_matching_block = textwrap.dedent('''\
Hello world!
# start
No match here
# end
# comment here
''')
with_non_matching_block_and_marker_end_not_after_newline = textwrap.dedent('''\
Hello world!
# start
No match here# end
# comment here
''')
with_matching_block = textwrap.dedent('''\
Hello world!
# start
Line 1 of block
Line 2 of block
# end
# comment here
''')
with_matching_block_and_extra_newline = textwrap.dedent('''\
Hello world!
# start
Line 1 of block
Line 2 of block
# end
# comment here
''')
with_matching_block_and_marker_end_not_after_newline = textwrap.dedent('''\
Hello world!
# start
Line 1 of block
Line 2 of block# end
# comment here
''')
content = six.text_type(os.linesep.join([
'Line 1 of block',
'Line 2 of block',
'']))
without_block = six.text_type(os.linesep.join([
'Hello world!',
'',
'# comment here',
'']))
with_non_matching_block = six.text_type(os.linesep.join([
'Hello world!',
'',
'# start',
'No match here',
'# end',
'# comment here',
'']))
with_non_matching_block_and_marker_end_not_after_newline = six.text_type(os.linesep.join([
'Hello world!',
'',
'# start',
'No match here# end',
'# comment here',
'']))
with_matching_block = six.text_type(os.linesep.join([
'Hello world!',
'',
'# start',
'Line 1 of block',
'Line 2 of block',
'# end',
'# comment here',
'']))
with_matching_block_and_extra_newline = six.text_type(os.linesep.join([
'Hello world!',
'',
'# start',
'Line 1 of block',
'Line 2 of block',
'',
'# end',
'# comment here',
'']))
with_matching_block_and_marker_end_not_after_newline = six.text_type(os.linesep.join([
'Hello world!',
'',
'# start',
'Line 1 of block',
'Line 2 of block# end',
'# comment here',
'']))
content_explicit_posix_newlines = ('Line 1 of block\n'
'Line 2 of block\n')
content_explicit_windows_newlines = ('Line 1 of block\r\n'
@ -2747,8 +2747,8 @@ class BlockreplaceTest(ModuleCase, SaltReturnAssertsMixin):
Test blockreplace when prepend_if_not_found=True and block doesn't
exist in file.
'''
expected = self.marker_start + '\n' + self.content + \
self.marker_end + '\n' + self.without_block
expected = self.marker_start + os.linesep + self.content + \
self.marker_end + os.linesep + self.without_block
# Pass 1: content ends in newline
self._write(name, self.without_block)
@ -2801,8 +2801,8 @@ class BlockreplaceTest(ModuleCase, SaltReturnAssertsMixin):
exist in file. Test with append_newline explicitly set to True.
'''
# Pass 1: content ends in newline
expected = self.marker_start + '\n' + self.content + \
'\n' + self.marker_end + '\n' + self.without_block
expected = self.marker_start + os.linesep + self.content + \
os.linesep + self.marker_end + os.linesep + self.without_block
self._write(name, self.without_block)
ret = self.run_state('file.blockreplace',
name=name,
@ -2827,8 +2827,8 @@ class BlockreplaceTest(ModuleCase, SaltReturnAssertsMixin):
self.assertEqual(self._read(name), expected)
# Pass 2: content does not end in newline
expected = self.marker_start + '\n' + self.content + \
self.marker_end + '\n' + self.without_block
expected = self.marker_start + os.linesep + self.content + \
self.marker_end + os.linesep + self.without_block
self._write(name, self.without_block)
ret = self.run_state('file.blockreplace',
name=name,
@ -2859,8 +2859,8 @@ class BlockreplaceTest(ModuleCase, SaltReturnAssertsMixin):
exist in file. Test with append_newline explicitly set to False.
'''
# Pass 1: content ends in newline
expected = self.marker_start + '\n' + self.content + \
self.marker_end + '\n' + self.without_block
expected = self.marker_start + os.linesep + self.content + \
self.marker_end + os.linesep + self.without_block
self._write(name, self.without_block)
ret = self.run_state('file.blockreplace',
name=name,
@ -2885,8 +2885,8 @@ class BlockreplaceTest(ModuleCase, SaltReturnAssertsMixin):
self.assertEqual(self._read(name), expected)
# Pass 2: content does not end in newline
expected = self.marker_start + '\n' + \
self.content.rstrip('\r\n') + self.marker_end + '\n' + \
expected = self.marker_start + os.linesep + \
self.content.rstrip('\r\n') + self.marker_end + os.linesep + \
self.without_block
self._write(name, self.without_block)
ret = self.run_state('file.blockreplace',
@ -2917,8 +2917,8 @@ class BlockreplaceTest(ModuleCase, SaltReturnAssertsMixin):
Test blockreplace when append_if_not_found=True and block doesn't
exist in file.
'''
expected = self.without_block + self.marker_start + '\n' + \
self.content + self.marker_end + '\n'
expected = self.without_block + self.marker_start + os.linesep + \
self.content + self.marker_end + os.linesep
# Pass 1: content ends in newline
self._write(name, self.without_block)
@ -2971,8 +2971,8 @@ class BlockreplaceTest(ModuleCase, SaltReturnAssertsMixin):
exist in file. Test with append_newline explicitly set to True.
'''
# Pass 1: content ends in newline
expected = self.without_block + self.marker_start + '\n' + \
self.content + '\n' + self.marker_end + '\n'
expected = self.without_block + self.marker_start + os.linesep + \
self.content + os.linesep + self.marker_end + os.linesep
self._write(name, self.without_block)
ret = self.run_state('file.blockreplace',
name=name,
@ -2997,8 +2997,8 @@ class BlockreplaceTest(ModuleCase, SaltReturnAssertsMixin):
self.assertEqual(self._read(name), expected)
# Pass 2: content does not end in newline
expected = self.without_block + self.marker_start + '\n' + \
self.content + self.marker_end + '\n'
expected = self.without_block + self.marker_start + os.linesep + \
self.content + self.marker_end + os.linesep
self._write(name, self.without_block)
ret = self.run_state('file.blockreplace',
name=name,
@ -3029,8 +3029,8 @@ class BlockreplaceTest(ModuleCase, SaltReturnAssertsMixin):
exist in file. Test with append_newline explicitly set to False.
'''
# Pass 1: content ends in newline
expected = self.without_block + self.marker_start + '\n' + \
self.content + self.marker_end + '\n'
expected = self.without_block + self.marker_start + os.linesep + \
self.content + self.marker_end + os.linesep
self._write(name, self.without_block)
ret = self.run_state('file.blockreplace',
name=name,
@ -3055,8 +3055,8 @@ class BlockreplaceTest(ModuleCase, SaltReturnAssertsMixin):
self.assertEqual(self._read(name), expected)
# Pass 2: content does not end in newline
expected = self.without_block + self.marker_start + '\n' + \
self.content.rstrip('\r\n') + self.marker_end + '\n'
expected = self.without_block + self.marker_start + os.linesep + \
self.content.rstrip('\r\n') + self.marker_end + os.linesep
self._write(name, self.without_block)
ret = self.run_state('file.blockreplace',
name=name,