예제 #1
0
 def test_slurp_file(self, mocker):
     mocker.patch('os.path.exists', side_effect=lambda x: True)
     m = mocker.mock_open(read_data='This is a test')
     if PY2:
         mocker.patch('__builtin__.open', m)
     else:
         mocker.patch('builtins.open', m)
     assert amc._slurp('some_file') == 'This is a test'
예제 #2
0
 def test_slurp_file(self, mocker):
     mocker.patch('os.path.exists', side_effect=lambda x: True)
     m = mocker.mock_open(read_data='This is a test')
     if PY2:
         mocker.patch('__builtin__.open', m)
     else:
         mocker.patch('builtins.open', m)
     assert amc._slurp('some_file') == 'This is a test'
예제 #3
0
 def test_slurp_file_with_newlines(self, mocker):
     mocker.patch('os.path.exists', side_effect=lambda x: True)
     m = mocker.mock_open(read_data='#!/usr/bin/python\ndef test(args):\nprint("hi")\n')
     if PY2:
         mocker.patch('__builtin__.open', m)
     else:
         mocker.patch('builtins.open', m)
     assert amc._slurp('some_file') == '#!/usr/bin/python\ndef test(args):\nprint("hi")\n'
예제 #4
0
 def test_slurp_nonexistent(self, mocker):
     mocker.patch('os.path.exists', side_effect=lambda x: False)
     with pytest.raises(ansible.errors.AnsibleError):
         amc._slurp('no_file')
예제 #5
0
 def test_slurp_nonexistent(self, mocker):
     mocker.patch('os.path.exists', side_effect=lambda x: False)
     with pytest.raises(ansible.errors.AnsibleError):
         amc._slurp('no_file')