def test_get_fact_current_op_meta(self):
        inventory = make_inventory(hosts=('anotherhost', ))
        state = State(inventory, Config())

        anotherhost = inventory.get_host('anotherhost')

        connect_all(state)
        state.current_op_global_kwargs = {
            'sudo': True,
            'sudo_user': '******',
            'use_sudo_password': True,
            'su_user': '******',
            'ignore_errors': False,
            'timeout': 10,
            'env': {
                'HELLO': 'WORLD'
            },
        }

        with patch('pyinfra.api.connectors.ssh.run_shell_command'
                   ) as fake_run_command:
            fake_run_command.return_value = MagicMock(), [('stdout',
                                                           'some-output')]
            fact_data = get_facts(state, 'command', ('yes', ))

        assert fact_data == {anotherhost: 'some-output'}

        fake_run_command.assert_called_with(
            state,
            anotherhost,
            'yes',
            print_input=False,
            print_output=False,
            shell_executable=None,
            su_user='******',
            sudo=True,
            sudo_user='******',
            timeout=10,
            env={'HELLO': 'WORLD'},
            use_sudo_password=True,
            return_combined_output=True,
        )
    def test_get_fact_error_ignore(self):
        inventory = make_inventory(hosts=('anotherhost', ))
        state = State(inventory, Config())

        anotherhost = inventory.get_host('anotherhost')

        connect_all(state)
        state.current_op_global_kwargs = {
            'sudo': False,
            'sudo_user': None,
            'use_sudo_password': False,
            'su_user': None,
            'ignore_errors': True,
            'timeout': None,
            'env': {},
        }

        with patch('pyinfra.api.connectors.ssh.run_shell_command'
                   ) as fake_run_command:
            fake_run_command.return_value = False, MagicMock()
            fact_data = get_facts(state, 'command', ('fail command', ))

        assert fact_data == {anotherhost: None}

        fake_run_command.assert_called_with(
            state,
            anotherhost,
            'fail command',
            print_input=False,
            print_output=False,
            shell_executable=None,
            su_user=None,
            sudo=False,
            sudo_user=None,
            timeout=None,
            env={},
            use_sudo_password=False,
            return_combined_output=True,
        )