aboutsummaryrefslogtreecommitdiffstats
path: root/tests/unit
diff options
context:
space:
mode:
Diffstat (limited to 'tests/unit')
-rw-r--r--tests/unit/cli/cmd_metric_test.py6
-rw-r--r--tests/unit/cli/cmd_plan_test.py5
-rw-r--r--tests/unit/cli/cmd_qpi_test.py5
-rw-r--r--tests/unit/util/env_test.py26
4 files changed, 15 insertions, 27 deletions
diff --git a/tests/unit/cli/cmd_metric_test.py b/tests/unit/cli/cmd_metric_test.py
index e121fb1e..cd496ad9 100644
--- a/tests/unit/cli/cmd_metric_test.py
+++ b/tests/unit/cli/cmd_metric_test.py
@@ -34,8 +34,10 @@ def test_run(runner):
def test_show(runner):
- result = runner.invoke(cli, ['metric', 'show', 'fake-metric'])
- assert result.output == ''
+ result = runner.invoke(cli, ['metric', 'show', 'dhrystone'])
+ assert 'Name: dhrystone' in result.output
+ assert 'Description: A synthetic computing benchmark program intended to be representative of' \
+ 'system (integer) programming.'
result = runner.invoke(cli, ['metric', 'show'])
assert 'Missing argument "name".' in result.output
diff --git a/tests/unit/cli/cmd_plan_test.py b/tests/unit/cli/cmd_plan_test.py
index 7c3335fc..30025ae0 100644
--- a/tests/unit/cli/cmd_plan_test.py
+++ b/tests/unit/cli/cmd_plan_test.py
@@ -32,8 +32,9 @@ def test_run(runner):
def test_show(runner):
- result = runner.invoke(cli, ['plan', 'show', 'fake-plan'])
- assert result.output == ''
+ result = runner.invoke(cli, ['plan', 'show', 'compute'])
+ assert 'Name: compute QPI' in result.output
+ assert 'Description: compute QPI profile'
result = runner.invoke(cli, ['plan', 'show'])
assert 'Missing argument "name".' in result.output
diff --git a/tests/unit/cli/cmd_qpi_test.py b/tests/unit/cli/cmd_qpi_test.py
index 7067d62c..3d2c2613 100644
--- a/tests/unit/cli/cmd_qpi_test.py
+++ b/tests/unit/cli/cmd_qpi_test.py
@@ -32,8 +32,9 @@ def test_run(runner):
def test_show(runner):
- result = runner.invoke(cli, ['qpi', 'show', 'fake-qpi'])
- assert result.output == ''
+ result = runner.invoke(cli, ['qpi', 'show', 'compute'])
+ assert 'Name: compute' in result.output
+ assert 'Description: sample performance index of computing' in result.output
result = runner.invoke(cli, ['qpi', 'show'])
assert 'Missing argument "name".' in result.output
diff --git a/tests/unit/util/env_test.py b/tests/unit/util/env_test.py
index 62d12a13..793d1e4e 100644
--- a/tests/unit/util/env_test.py
+++ b/tests/unit/util/env_test.py
@@ -72,12 +72,10 @@ def test_init(ansible_envsetup):
assert ansible_envsetup.host_ip_list == []
-def test_setup_exception(capsys, mocker, ansible_envsetup, hostfile):
+def test_setup_exception(mocker, ansible_envsetup, hostfile):
with mock.patch.object(AnsibleEnvSetup, 'check_hostfile', side_effect=RuntimeError()):
mock_os = mocker.patch('sys.exit')
ansible_envsetup.setup({'hostfile': str(hostfile)})
- out, error = capsys.readouterr()
- assert out == '\n'
assert mock_os.call_count == 1
@@ -178,21 +176,17 @@ def test_pass_keypair_to_remote_failed(mocker, ansible_envsetup):
assert "Failed on passing keypair to remote." in str(excinfo.value)
-def test_pass_keypair(monkeypatch, capsys, mocker, ansible_envsetup):
+def test_pass_keypair(monkeypatch, mocker, ansible_envsetup):
monkeypatch.setattr(time, 'sleep', lambda s: None)
mock_os = mocker.patch('os.system')
ansible_envsetup._pass_keypair('10.20.0.3', str(private_key))
assert mock_os.call_count == 2
- out, error = capsys.readouterr()
- assert "Pass keypair to remote hosts 10.20.0.3 successfully" in out
-def test_pass_keypair_exception(capsys, ansible_envsetup):
+def test_pass_keypair_exception(ansible_envsetup):
with mock.patch('os.system', side_effect=Exception()) as mock_os:
result = ansible_envsetup._pass_keypair('10.20.0.3', str(private_key))
assert result is False
- out, error = capsys.readouterr()
- assert out == '\n'
assert mock_os.call_count == 1
@@ -304,20 +298,10 @@ def test_ssh_is_ok(mocker, ansible_envsetup, private_key, stderrinfo, expected):
test_ssh_client.exec_command.assert_called_with('uname')
-@pytest.mark.parametrize("attempts, expected", [
- (1,
- 'Check hosts 10.20.0.3 ssh connectivity...\n1 times ssh test......failed.\n'),
- (2,
- 'Check hosts 10.20.0.3 ssh connectivity...\n'
- '1 times ssh test......failed.\n'
- '2 times ssh test......failed.\n')
-])
-def test_ssh_exception(capsys, monkeypatch, mocker, ansible_envsetup, attempts, expected):
+def test_ssh_exception(monkeypatch, mocker, ansible_envsetup):
monkeypatch.setattr(time, 'sleep', lambda s: None)
mock_sshclient = mocker.patch('paramiko.SSHClient')
test_ssh_client = mock_sshclient.return_value
test_ssh_client.exec_command.side_effect = socket.error()
- result = ansible_envsetup._ssh_is_ok('10.20.0.3', str(private_key), attempts=attempts)
- out, error = capsys.readouterr()
- assert expected == out
+ result = ansible_envsetup._ssh_is_ok('10.20.0.3', str(private_key), attempts=1)
assert result is False