def test_running(self):
        ret = [{'comment': '', 'changes': {}, 'name': 'salt', 'result': True},
               {'changes': {},
                'comment': 'The service salt is already running',
                'name': 'salt', 'result': True},
               {'changes': 'saltstack',
                'comment': 'The service salt is already running',
                'name': 'salt', 'result': True},
               {'changes': {},
                'comment': 'Service salt is set to start', 'name': 'salt',
                'result': None},
               {'changes': 'saltstack',
                'comment': 'Started Service salt', 'name': 'salt',
                'result': True},
               {'changes': {},
                'comment': 'The service salt is already running',
                'name': 'salt', 'result': True}]

        tmock = MagicMock(return_value=True)
        fmock = MagicMock(return_value=False)
        vmock = MagicMock(return_value="salt")
        with patch.object(service, '_enabled_used_error', vmock):
            self.assertEqual(service.running("salt", enabled=1), 'salt')

        with patch.object(service, '_available', fmock):
            self.assertDictEqual(service.running("salt"), ret[0])

        with patch.object(service, '_available', tmock):
            with contextlib.nested(
                patch.dict(service.__opts__, {'test': False}),
                patch.dict(
                    service.__salt__,
                    {'service.enabled': tmock, 'service.status': tmock}
                )
            ):
                self.assertDictEqual(service.running("salt"), ret[1])

                # service was enabled and running, no changes
                mock = MagicMock(return_value={'changes': 'saltstack'})
                with contextlib.nested(
                    patch.dict(service.__opts__, {'test': False}),
                    patch.dict(
                        service.__salt__,
                        {'service.enabled':
                         MagicMock(side_effect=[False, True]),
                         'service.status': tmock}
                    ),
                    patch.object(service, '_enable', mock)
                ):
                    self.assertDictEqual(service.running("salt", True), ret[2])

                with contextlib.nested(
                    patch.dict(service.__opts__, {'test': False}),
                    patch.dict(
                        service.__salt__,
                        {'service.enabled':
                         MagicMock(side_effect=[True, False]),
                         'service.status': tmock}
                    ),
                    patch.object(service, '_disable', mock)
                ):
                    self.assertDictEqual(service.running("salt", False),
                                         ret[2])

                with patch.dict(service.__opts__, {'test': True}):
                    self.assertDictEqual(service.running("salt"), ret[5])

                with contextlib.nested(
                    patch.dict(
                        service.__salt__,
                        {'service.status': fmock}
                    ),
                    patch.dict(service.__opts__, {'test': True})
                ):
                    self.assertDictEqual(service.running("salt"), ret[3])

                with contextlib.nested(
                    patch.dict(service.__opts__, {'test': False}),
                    patch.dict(
                        service.__salt__, {
                            'service.status':
                            MagicMock(side_effect=[False, True]),
                            'service.enabled':
                            MagicMock(side_effect=[False, True]),
                            'service.start':
                            MagicMock(return_value="stack")}),
                    patch.object(
                        service, '_enable',
                        MagicMock(return_value={'changes': 'saltstack'}))
                ):
                    self.assertDictEqual(service.running("salt", True), ret[4])
Override write_extra_resources to produce plugin and annotation processor files.
dataset/ETHPy150Open saltstack/salt/tests/unit/states/service_test.py/ServiceTestCase.test_running--crossover with--dataset/ETHPy150Open pantsbuild/pants/src/python/pants/backend/jvm/tasks/jvm_compile/zinc/zinc_compile.py/BaseZincCompile.write_extra_resources