Update mock_open usage to reflect read_data type enforcement

This commit is contained in:
Erik Johnson 2018-06-23 15:04:47 -05:00
parent 374a8ce31f
commit a13d1fe1a0
No known key found for this signature in database
GPG key ID: 5E5583C437808F3F
5 changed files with 5 additions and 7 deletions

View file

@ -56,7 +56,7 @@ class BTMPBeaconTestCase(TestCase, LoaderModuleMockMixin):
self.assertEqual(ret, (True, 'Valid beacon configuration'))
with patch('salt.utils.files.fopen', mock_open()) as m_open:
with patch('salt.utils.files.fopen', mock_open(b'')) as m_open:
ret = btmp.beacon(config)
call_args = next(six.itervalues(m_open.filehandles))[0].call.args
assert call_args == (btmp.BTMP, 'rb'), call_args

View file

@ -56,7 +56,7 @@ class WTMPBeaconTestCase(TestCase, LoaderModuleMockMixin):
self.assertEqual(ret, (True, 'Valid beacon configuration'))
with patch('salt.utils.files.fopen', mock_open()) as m_open:
with patch('salt.utils.files.fopen', mock_open(b'')) as m_open:
ret = wtmp.beacon(config)
call_args = next(six.itervalues(m_open.filehandles))[0].call.args
assert call_args == (wtmp.WTMP, 'rb'), call_args

View file

@ -114,7 +114,7 @@ class HostsTestCase(TestCase, LoaderModuleMockMixin):
with patch('salt.modules.hosts.__get_hosts_filename',
MagicMock(return_value='/etc/hosts')), \
patch('os.path.isfile', MagicMock(return_value=True)), \
patch('salt.utils.files.fopen', mock_open()):
patch('salt.utils.files.fopen', mock_open(b'')):
mock_opt = MagicMock(return_value=None)
with patch.dict(hosts.__salt__, {'config.option': mock_opt}):
self.assertTrue(hosts.set_host('10.10.10.10', 'Salt1'))
@ -212,7 +212,7 @@ class HostsTestCase(TestCase, LoaderModuleMockMixin):
'''
Tests if specified host entry gets removed from the hosts file
'''
with patch('salt.utils.files.fopen', mock_open()), \
with patch('salt.utils.files.fopen', mock_open(b'')), \
patch('salt.modules.hosts.__get_hosts_filename',
MagicMock(return_value='/etc/hosts')), \
patch('salt.modules.hosts.has_pair',

View file

@ -900,7 +900,7 @@ class StateTestCase(TestCase, LoaderModuleMockMixin):
mock):
with patch(
'salt.utils.files.fopen',
mock_open()):
mock_open(b'')):
self.assertTrue(
state.sls(arg,
None,

View file

@ -75,13 +75,11 @@ class SSHConfigRosterTestCase(TestCase, mixins.LoaderModuleMockMixin):
def test_all(self):
with mock.patch('salt.utils.files.fopen', self.mock_fp):
with mock.patch('salt.roster.sshconfig._get_ssh_config_file'):
self.mock_fp.return_value.__iter__.return_value = _SAMPLE_SSH_CONFIG.splitlines()
targets = sshconfig.targets('*')
self.assertEqual(targets, _ALL)
def test_abc_glob(self):
with mock.patch('salt.utils.files.fopen', self.mock_fp):
with mock.patch('salt.roster.sshconfig._get_ssh_config_file'):
self.mock_fp.return_value.__iter__.return_value = _SAMPLE_SSH_CONFIG.splitlines()
targets = sshconfig.targets('abc*')
self.assertEqual(targets, _ABC_GLOB)