1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- # -*- coding: utf-8 -*-
- '''
- unit tests for the script engine
- '''
- # Import Python libs
- from __future__ import absolute_import, print_function, unicode_literals
- # Import Salt Testing Libs
- from tests.support.mixins import LoaderModuleMockMixin
- from tests.support.unit import TestCase
- from tests.support.mock import patch
- # Import Salt Libs
- import salt.config
- import salt.engines.script as script
- from salt.exceptions import CommandExecutionError
- class EngineScriptTestCase(TestCase, LoaderModuleMockMixin):
- '''
- Test cases for salt.engine.script
- '''
- def setup_loader_modules(self):
- opts = salt.config.DEFAULT_MASTER_OPTS
- return {
- script: {
- '__opts__': opts
- }
- }
- def test__get_serializer(self):
- '''
- Test known serializer is returned or exception is raised
- if unknown serializer
- '''
- for serializers in ('json', 'yaml', 'msgpack'):
- self.assertTrue(script._get_serializer(serializers))
- with self.assertRaises(CommandExecutionError):
- script._get_serializer('bad')
- def test__read_stdout(self):
- '''
- Test we can yield stdout
- '''
- with patch('subprocess.Popen') as popen_mock:
- popen_mock.stdout.readline.return_value = 'test'
- self.assertEqual(next(script._read_stdout(popen_mock)), 'test')
|