Skip to content

Commit

Permalink
more test fixes; now passing locally on py26, py27, py34
Browse files Browse the repository at this point in the history
  • Loading branch information
jantman committed Jun 13, 2015
1 parent 3c5db49 commit 16d449f
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 18 deletions.
3 changes: 1 addition & 2 deletions awslimitchecker/tests/test_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,14 @@ def test_init_thresholds(self):
mock_bar.return_value = mock_svc2
svcs = {'SvcFoo': mock_foo, 'SvcBar': mock_bar}
with patch.dict('awslimitchecker.checker._services',
values=self.svcs, clear=True):
values=svcs, clear=True):
with patch.multiple(
'awslimitchecker.checker',
logger=DEFAULT,
_get_version=DEFAULT,
_get_project_url=DEFAULT,
autospec=True,
) as mocks:
mock_logger = mocks['logger']
mock_version = mocks['_get_version']
mock_project_url = mocks['_get_project_url']
mock_version.return_value = 'MVER'
Expand Down
7 changes: 6 additions & 1 deletion awslimitchecker/tests/test_limit.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@

from mock import Mock, patch, call
import pytest
import sys
from awslimitchecker.limit import AwsLimit, AwsLimitUsage


Expand Down Expand Up @@ -71,7 +72,11 @@ def test_init_valueerror(self):
11,
7
)
assert excinfo.value.message == "critical threshold must be greater " \
if sys.version_info[0] > 2:
msg = excinfo.value.args[0]
else:
msg = excinfo.value.message
assert msg == "critical threshold must be greater " \
"than warning threshold"

def test_init_type(self):
Expand Down
27 changes: 12 additions & 15 deletions awslimitchecker/tests/test_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import pytest
import sys
import logging
import json
from mock import patch, call, Mock, DEFAULT

import awslimitchecker.runner as runner
Expand Down Expand Up @@ -183,15 +184,15 @@ def test_entry_iam_policy(self):
]

def test_iam_policy(self, capsys):
expected = '{\n "baz": "blam", \n "foo": "bar"\n}\n'
expected = {"baz": "blam", "foo": "bar"}
mock_checker = Mock(spec_set=AwsLimitChecker)
mock_checker.get_required_iam_policy.return_value = {
'foo': 'bar',
'baz': 'blam',
}
runner.iam_policy(mock_checker)
out, err = capsys.readouterr()
assert out == expected
assert json.loads(out) == expected
assert err == ''
assert mock_checker.mock_calls == [
call.get_required_iam_policy()
Expand Down Expand Up @@ -271,7 +272,7 @@ def test_entry_verbose(self, capsys):
with patch('awslimitchecker.runner.logger.setLevel'
'') as mock_set_level:
with pytest.raises(SystemExit) as excinfo:
mocks['AwsLimitChecker'].return_value = 6
mocks['check_thresholds'].return_value = 6
runner.console_entry_point()
out, err = capsys.readouterr()
assert err == ''
Expand All @@ -290,12 +291,12 @@ def test_entry_debug(self, capsys):
with patch('awslimitchecker.runner.logger.setLevel'
'') as mock_set_level:
with pytest.raises(SystemExit) as excinfo:
mocks['AwsLimitChecker'].return_value = 7
mocks['check_thresholds'].return_value = 7
runner.console_entry_point()
out, err = capsys.readouterr()
assert err == ''
assert out == ''
assert excinfo.value.code == 7
assert excinfo.value.args[0] == 7
assert mock_set_level.mock_calls == [call(logging.DEBUG)]

def test_entry_warning(self):
Expand All @@ -306,11 +307,9 @@ def test_entry_warning(self):
AwsLimitChecker=DEFAULT,
check_thresholds=DEFAULT,
) as mocks:
with patch('awslimitchecker.runner.logger.setLevel'
'') as mock_set_level:
with pytest.raises(SystemExit) as excinfo:
mocks['check_thresholds'].return_value = 8
runner.console_entry_point()
with pytest.raises(SystemExit) as excinfo:
mocks['check_thresholds'].return_value = 8
runner.console_entry_point()
assert excinfo.value.code == 8
assert mocks['AwsLimitChecker'].mock_calls == [
call(warning_threshold=50, critical_threshold=99)
Expand All @@ -324,11 +323,9 @@ def test_entry_critical(self):
AwsLimitChecker=DEFAULT,
check_thresholds=DEFAULT,
) as mocks:
with patch('awslimitchecker.runner.logger.setLevel'
'') as mock_set_level:
with pytest.raises(SystemExit) as excinfo:
mocks['check_thresholds'].return_value = 9
runner.console_entry_point()
with pytest.raises(SystemExit) as excinfo:
mocks['check_thresholds'].return_value = 9
runner.console_entry_point()
assert excinfo.value.code == 9
assert mocks['AwsLimitChecker'].mock_calls == [
call(warning_threshold=80, critical_threshold=95)
Expand Down

0 comments on commit 16d449f

Please sign in to comment.