import os
import subprocess

import pytest
import salt.client.ssh.shell as shell


@pytest.fixture
def keys(tmp_path):
    pub_key = tmp_path / "ssh" / "testkey.pub"
    priv_key = tmp_path / "ssh" / "testkey"
    yield {"pub_key": str(pub_key), "priv_key": str(priv_key)}


@pytest.mark.skip_on_windows(reason="Windows does not support salt-ssh")
@pytest.mark.skip_if_binaries_missing("ssh", "ssh-keygen", check_all=True)
class TestSSHShell:
    def test_ssh_shell_key_gen(self, keys):
        """
        Test ssh key_gen
        """
        shell.gen_key(keys["priv_key"])
        for fp in keys.keys():
            assert os.path.exists(keys[fp])

        # verify there is not a passphrase set on key
        ret = subprocess.check_output(
            ["ssh-keygen", "-f", keys["priv_key"], "-y"], timeout=30,
        )
        assert ret.decode().startswith("ssh-rsa")

import subprocess
import types

import pytest
import salt.client.ssh.shell as shell


@pytest.fixture
def keys(tmp_path):
    pub_key = tmp_path / "ssh" / "testkey.pub"
    priv_key = tmp_path / "ssh" / "testkey"
    return types.SimpleNamespace(pub_key=pub_key, priv_key=priv_key)


@pytest.mark.skip_on_windows(reason="Windows does not support salt-ssh")
@pytest.mark.skip_if_binaries_missing("ssh", "ssh-keygen", check_all=True)
def test_ssh_shell_key_gen(keys):
    """
    Test ssh key_gen
    """
    shell.gen_key(str(keys.priv_key))
    assert keys.priv_key.exists()
    assert keys.pub_key.exists()
    # verify there is not a passphrase set on key
    ret = subprocess.check_output(
        ["ssh-keygen", "-f", str(keys.priv_key), "-y"], timeout=30,
    )
    assert ret.decode().startswith("ssh-rsa")

Use commit suggestion to use types
Use commit suggestion to use types

Co-authored-by: Pedro Algarvio <4410d99cefe57ec2c2cdbd3f1d5cf862bb4fb6f8@algarvio.me>

- import os
  import subprocess
+ import types
  
  import pytest
  import salt.client.ssh.shell as shell
  
  
  @pytest.fixture
  def keys(tmp_path):
      pub_key = tmp_path / "ssh" / "testkey.pub"
      priv_key = tmp_path / "ssh" / "testkey"
-     yield {"pub_key": str(pub_key), "priv_key": str(priv_key)}
+     return types.SimpleNamespace(pub_key=pub_key, priv_key=priv_key)
  
  
  @pytest.mark.skip_on_windows(reason="Windows does not support salt-ssh")
  @pytest.mark.skip_if_binaries_missing("ssh", "ssh-keygen", check_all=True)
- class TestSSHShell:
-     def test_ssh_shell_key_gen(self, keys):
+ def test_ssh_shell_key_gen(keys):
-         """
+     """
-         Test ssh key_gen
+     Test ssh key_gen
-         """
+     """
-         shell.gen_key(keys["priv_key"])
+     shell.gen_key(str(keys.priv_key))
-         for fp in keys.keys():
-             assert os.path.exists(keys[fp])
+     assert keys.priv_key.exists()
+     assert keys.pub_key.exists()
+     # verify there is not a passphrase set on key
+     ret = subprocess.check_output(
+         ["ssh-keygen", "-f", str(keys.priv_key), "-y"], timeout=30,
+     )
+     assert ret.decode().startswith("ssh-rsa")
  
-         # verify there is not a passphrase set on key
-         ret = subprocess.check_output(
-             ["ssh-keygen", "-f", keys["priv_key"], "-y"], timeout=30,
-         )
-         assert ret.decode().startswith("ssh-rsa")
- 
Use commit suggestion to use types
## Code Before:
import os
import subprocess

import pytest
import salt.client.ssh.shell as shell


@pytest.fixture
def keys(tmp_path):
    pub_key = tmp_path / "ssh" / "testkey.pub"
    priv_key = tmp_path / "ssh" / "testkey"
    yield {"pub_key": str(pub_key), "priv_key": str(priv_key)}


@pytest.mark.skip_on_windows(reason="Windows does not support salt-ssh")
@pytest.mark.skip_if_binaries_missing("ssh", "ssh-keygen", check_all=True)
class TestSSHShell:
    def test_ssh_shell_key_gen(self, keys):
        """
        Test ssh key_gen
        """
        shell.gen_key(keys["priv_key"])
        for fp in keys.keys():
            assert os.path.exists(keys[fp])

        # verify there is not a passphrase set on key
        ret = subprocess.check_output(
            ["ssh-keygen", "-f", keys["priv_key"], "-y"], timeout=30,
        )
        assert ret.decode().startswith("ssh-rsa")

## Instruction:
Use commit suggestion to use types
## Code After:
import subprocess
import types

import pytest
import salt.client.ssh.shell as shell


@pytest.fixture
def keys(tmp_path):
    pub_key = tmp_path / "ssh" / "testkey.pub"
    priv_key = tmp_path / "ssh" / "testkey"
    return types.SimpleNamespace(pub_key=pub_key, priv_key=priv_key)


@pytest.mark.skip_on_windows(reason="Windows does not support salt-ssh")
@pytest.mark.skip_if_binaries_missing("ssh", "ssh-keygen", check_all=True)
def test_ssh_shell_key_gen(keys):
    """
    Test ssh key_gen
    """
    shell.gen_key(str(keys.priv_key))
    assert keys.priv_key.exists()
    assert keys.pub_key.exists()
    # verify there is not a passphrase set on key
    ret = subprocess.check_output(
        ["ssh-keygen", "-f", str(keys.priv_key), "-y"], timeout=30,
    )
    assert ret.decode().startswith("ssh-rsa")
