aboutsummaryrefslogtreecommitdiffstats
path: root/tests/unit
diff options
context:
space:
mode:
Diffstat (limited to 'tests/unit')
-rw-r--r--tests/unit/cli/cmd_metric_test.py14
-rw-r--r--tests/unit/cli/cmd_plan_test.py9
-rw-r--r--tests/unit/cli/cmd_qpi_test.py11
-rw-r--r--tests/unit/util/env_test.py26
4 files changed, 25 insertions, 35 deletions
diff --git a/tests/unit/cli/cmd_metric_test.py b/tests/unit/cli/cmd_metric_test.py
index 30f3448a..cd496ad9 100644
--- a/tests/unit/cli/cmd_metric_test.py
+++ b/tests/unit/cli/cmd_metric_test.py
@@ -1,5 +1,5 @@
###############################################################
-# Copyright (c) 2016 ZTE Corp and others.
+# Copyright (c) 2017 taseer94@gmail.com and others.
#
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Apache License, Version 2.0
@@ -8,8 +8,8 @@
##############################################################################
import pytest
-from click.testing import CliRunner
+from click.testing import CliRunner
from qtip.cli.entry import cli
@@ -20,7 +20,9 @@ def runner():
def test_list(runner):
result = runner.invoke(cli, ['metric', 'list'])
- assert result.output == ''
+ assert 'dhrystone' and 'whetstone' and 'dpi' and \
+ 'ramspeed' and 'fake-metric' and 'ssl' \
+ in result.output
def test_run(runner):
@@ -32,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 1708c340..30025ae0 100644
--- a/tests/unit/cli/cmd_plan_test.py
+++ b/tests/unit/cli/cmd_plan_test.py
@@ -1,5 +1,5 @@
###############################################################
-# Copyright (c) 2016 ZTE Corp and others.
+# Copyright (c) 2017 taseer94@gmail.com and others.
#
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Apache License, Version 2.0
@@ -20,7 +20,7 @@ def runner():
def test_list(runner):
result = runner.invoke(cli, ['plan', 'list'])
- assert result.output == ''
+ assert 'Plan' and 'compute' and 'sample' in result.output
def test_run(runner):
@@ -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 485d5462..3d2c2613 100644
--- a/tests/unit/cli/cmd_qpi_test.py
+++ b/tests/unit/cli/cmd_qpi_test.py
@@ -1,5 +1,5 @@
###############################################################
-# Copyright (c) 2016 ZTE Corp and others.
+# Copyright (c) 2017 taseer94@gmail.com and others.
#
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Apache License, Version 2.0
@@ -8,9 +8,9 @@
##############################################################################
import pytest
-from click.testing import CliRunner
from qtip.cli.entry import cli
+from click.testing import CliRunner
@pytest.fixture(scope="module")
@@ -20,7 +20,7 @@ def runner():
def test_list(runner):
result = runner.invoke(cli, ['qpi', 'list'])
- assert result.output == ''
+ assert 'QPIs' and 'compute' in result.output
def test_run(runner):
@@ -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