Skip to content

Commit

Permalink
Multiple windows test fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
dwoz committed Jul 25, 2018
1 parent e6dace3 commit a89019e
Showing 1 changed file with 17 additions and 12 deletions.
29 changes: 17 additions & 12 deletions tests/unit/modules/test_file.py
Expand Up @@ -935,7 +935,7 @@ def _get_body(content):
else:
return salt.utils.data.decode_list(ret, to_str=True)

@patch('os.path.realpath', MagicMock())
@patch('os.path.realpath', MagicMock(wraps=lambda x: x))
@patch('os.path.isfile', MagicMock(return_value=True))
def test_delete_line_in_empty_file(self):
'''
Expand Down Expand Up @@ -977,7 +977,7 @@ def test_line_delete_no_match(self):
with patch('salt.utils.atomicfile.atomic_open', atomic_opener):
self.assertFalse(filemod.line('foo', content='foo', match=match, mode=mode))

@patch('os.path.realpath', MagicMock())
@patch('os.path.realpath', MagicMock(wraps=lambda x: x))
@patch('os.path.isfile', MagicMock(return_value=True))
def test_line_modecheck_failure(self):
'''
Expand All @@ -990,7 +990,7 @@ def test_line_modecheck_failure(self):
filemod.line('foo', mode=mode)
self.assertIn(err_msg, six.text_type(cmd_err))

@patch('os.path.realpath', MagicMock())
@patch('os.path.realpath', MagicMock(wraps=lambda x: x))
@patch('os.path.isfile', MagicMock(return_value=True))
def test_line_no_content(self):
'''
Expand All @@ -1003,7 +1003,7 @@ def test_line_no_content(self):
self.assertIn('Content can only be empty if mode is "delete"',
six.text_type(cmd_err))

@patch('os.path.realpath', MagicMock())
@patch('os.path.realpath', MagicMock(wraps=lambda x: x))
@patch('os.path.isfile', MagicMock(return_value=True))
@patch('os.stat', MagicMock())
def test_line_insert_no_location_no_before_no_after(self):
Expand Down Expand Up @@ -1134,10 +1134,13 @@ def test_line_insert_multi_line_content_after_unicode(self, name):
See issue #48113
:return:
'''
file_content = 'This is a line\nThis is another line'
file_modified = salt.utils.stringutils.to_str('This is a line\n'
'This is another line\n'
'This is a line with unicode Ŷ')
file_content = 'This is a line{}This is another line'.format(os.linesep)
file_modified = salt.utils.stringutils.to_str('This is a line{}'
'This is another line{}'
'This is a line with unicode Ŷ'.format(
os.linesep, os.linesep
)
)
cfg_content = "This is a line with unicode Ŷ"
isfile_mock = MagicMock(side_effect=lambda x: True if x == name else DEFAULT)
for after_line in ['This is another line']:
Expand Down Expand Up @@ -1204,7 +1207,7 @@ def test_line_insert_before(self, name):
expected = self._get_body(file_modified)
assert writelines_content[0] == expected, (writelines_content[0], expected)

@patch('os.path.realpath', MagicMock())
@patch('os.path.realpath', MagicMock(wraps=lambda x: x))
@patch('os.path.isfile', MagicMock(return_value=True))
@patch('os.stat', MagicMock())
def test_line_assert_exception_pattern(self):
Expand Down Expand Up @@ -1538,7 +1541,7 @@ def test_line_insert_ensure_beforeafter_twolines_exists(self, name):
# No changes should have been made
assert result is False

@patch('os.path.realpath', MagicMock())
@patch('os.path.realpath', MagicMock(wraps=lambda x: x))
@patch('os.path.isfile', MagicMock(return_value=True))
@patch('os.stat', MagicMock())
def test_line_insert_ensure_beforeafter_rangelines(self):
Expand All @@ -1548,8 +1551,10 @@ def test_line_insert_ensure_beforeafter_rangelines(self):
'''
cfg_content = 'EXTRA_GROUPS="dialout cdrom floppy audio video plugdev users"'
# pylint: disable=W1401
file_content = 'NAME_REGEX="^[a-z][-a-z0-9_]*\$"\nSETGID_HOME=no\nADD_EXTRA_GROUPS=1\n' \
'SKEL_IGNORE_REGEX="dpkg-(old|new|dist|save)"'
file_content = 'NAME_REGEX="^[a-z][-a-z0-9_]*\$"{}SETGID_HOME=no{}ADD_EXTRA_GROUPS=1{}' \
'SKEL_IGNORE_REGEX="dpkg-(old|new|dist|save)"'.format(
os.linesep, os.linesep, os.linesep
)
# pylint: enable=W1401
after, before = file_content.split(os.linesep)[0], file_content.split(os.linesep)[-1]
for (_after, _before) in [(after, before), ('NAME_.*', 'SKEL_.*')]:
Expand Down

0 comments on commit a89019e

Please sign in to comment.