Merge "Superfluous imports are now mocked"
This commit is contained in:
commit
97d82bfeaa
|
@ -19,16 +19,18 @@ test_fail_if_no_hosts
|
||||||
Tests for `fail_if_no_hosts` callback plugin.
|
Tests for `fail_if_no_hosts` callback plugin.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
try:
|
||||||
|
from unittest import mock
|
||||||
|
except ImportError:
|
||||||
|
import mock
|
||||||
|
|
||||||
|
from validations_common.tests import base
|
||||||
|
from validations_common.tests import fakes
|
||||||
|
|
||||||
import validations_common.library.reportentry as validation
|
import validations_common.library.reportentry as validation
|
||||||
from validations_common.callback_plugins import fail_if_no_hosts
|
from validations_common.callback_plugins import fail_if_no_hosts
|
||||||
from validations_common.tests import base
|
|
||||||
|
|
||||||
from ansible.plugins.callback import CallbackBase
|
from ansible.plugins.callback import CallbackBase
|
||||||
from ansible.executor.stats import AggregateStats
|
|
||||||
|
|
||||||
from unittest import mock
|
|
||||||
|
|
||||||
|
|
||||||
class TestFailIfNoHosts(base.TestCase):
|
class TestFailIfNoHosts(base.TestCase):
|
||||||
|
@ -64,7 +66,7 @@ class TestFailIfNoHosts(base.TestCase):
|
||||||
the callback calls sys.exit.
|
the callback calls sys.exit.
|
||||||
"""
|
"""
|
||||||
callback = fail_if_no_hosts.CallbackModule()
|
callback = fail_if_no_hosts.CallbackModule()
|
||||||
stats = AggregateStats()
|
stats = mock.MagicMock()
|
||||||
|
|
||||||
callback.v2_playbook_on_stats(stats)
|
callback.v2_playbook_on_stats(stats)
|
||||||
mock_exit.assert_called_once_with(10)
|
mock_exit.assert_called_once_with(10)
|
||||||
|
@ -82,7 +84,7 @@ class TestFailIfNoHosts(base.TestCase):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
callback = fail_if_no_hosts.CallbackModule()
|
callback = fail_if_no_hosts.CallbackModule()
|
||||||
stats = AggregateStats()
|
stats = mock.MagicMock()
|
||||||
|
|
||||||
stats.processed = {
|
stats.processed = {
|
||||||
'system_foo': 'foo',
|
'system_foo': 'foo',
|
||||||
|
|
|
@ -19,13 +19,16 @@ test_http_json
|
||||||
Tests for `http_json` callback plugin.
|
Tests for `http_json` callback plugin.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
try:
|
||||||
|
from unittest import mock
|
||||||
|
except ImportError:
|
||||||
|
import mock
|
||||||
|
|
||||||
|
from validations_common.tests import base
|
||||||
|
from validations_common.tests import fakes
|
||||||
|
|
||||||
import validations_common.library.reportentry as validation
|
import validations_common.library.reportentry as validation
|
||||||
from validations_common.callback_plugins import http_json
|
from validations_common.callback_plugins import http_json
|
||||||
from validations_common.tests import base
|
|
||||||
|
|
||||||
from unittest import mock
|
|
||||||
|
|
||||||
|
|
||||||
class TestHttpJson(base.TestCase):
|
class TestHttpJson(base.TestCase):
|
||||||
|
|
|
@ -19,12 +19,15 @@ test_validation_json
|
||||||
Tests for `validation_json` callback plugin.
|
Tests for `validation_json` callback plugin.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
try:
|
||||||
|
from unittest import mock
|
||||||
|
except ImportError:
|
||||||
|
import mock
|
||||||
|
|
||||||
|
from validations_common.tests import base
|
||||||
|
from validations_common.tests import fakes
|
||||||
|
|
||||||
import validations_common.library.reportentry as validation
|
import validations_common.library.reportentry as validation
|
||||||
from validations_common.tests import base
|
|
||||||
|
|
||||||
from unittest import mock
|
|
||||||
|
|
||||||
|
|
||||||
class TestValidationJson(base.TestCase):
|
class TestValidationJson(base.TestCase):
|
||||||
|
|
|
@ -19,17 +19,18 @@ test_validation_output
|
||||||
Tests for `validation_output` callback plugin.
|
Tests for `validation_output` callback plugin.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
try:
|
||||||
|
from unittest import mock
|
||||||
|
except ImportError:
|
||||||
|
import mock
|
||||||
|
|
||||||
from unittest import mock
|
from validations_common.tests import base
|
||||||
|
from validations_common.tests import fakes
|
||||||
|
|
||||||
from ansible.executor.stats import AggregateStats
|
|
||||||
from ansible.parsing.ajson import AnsibleJSONEncoder
|
|
||||||
from ansible.playbook import Playbook
|
|
||||||
from ansible.plugins.callback import CallbackBase
|
from ansible.plugins.callback import CallbackBase
|
||||||
|
|
||||||
import validations_common.library.reportentry as validation
|
import validations_common.library.reportentry as validation
|
||||||
from validations_common.callback_plugins import validation_output
|
from validations_common.callback_plugins import validation_output
|
||||||
from validations_common.tests import base
|
|
||||||
|
|
||||||
|
|
||||||
class MockStats(mock.MagicMock):
|
class MockStats(mock.MagicMock):
|
||||||
|
|
|
@ -21,13 +21,19 @@ Tests for `validation_stdout` callback plugin.
|
||||||
"""
|
"""
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
from unittest import mock
|
|
||||||
|
|
||||||
from ansible.plugins.callback import CallbackBase
|
try:
|
||||||
|
from unittest import mock
|
||||||
|
except ImportError:
|
||||||
|
import mock
|
||||||
|
|
||||||
|
from validations_common.tests import base
|
||||||
|
from validations_common.tests import fakes
|
||||||
|
|
||||||
import validations_common.library.reportentry as validation
|
import validations_common.library.reportentry as validation
|
||||||
from validations_common.callback_plugins import validation_stdout
|
from validations_common.callback_plugins import validation_stdout
|
||||||
from validations_common.tests import base
|
|
||||||
|
from ansible.plugins.callback import CallbackBase
|
||||||
|
|
||||||
|
|
||||||
def is_iso_time(time_string):
|
def is_iso_time(time_string):
|
||||||
|
|
|
@ -0,0 +1,24 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||||
|
# not use this file except in compliance with the License. You may obtain
|
||||||
|
# a copy of the License at
|
||||||
|
#
|
||||||
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
#
|
||||||
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
|
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||||
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
|
# License for the specific language governing permissions and limitations
|
||||||
|
# under the License.
|
||||||
|
|
||||||
|
import sys
|
||||||
|
try:
|
||||||
|
from unittest import mock
|
||||||
|
except ImportError:
|
||||||
|
import mock
|
||||||
|
|
||||||
|
#This section mocks unnecessary module imports.
|
||||||
|
|
||||||
|
sys.modules['ansible.parsing.ajson'] = mock.MagicMock()
|
||||||
|
sys.modules['prettytable'] = mock.MagicMock()
|
|
@ -12,9 +12,15 @@
|
||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
from unittest import mock
|
try:
|
||||||
from validations_common.library import advanced_format
|
from unittest import mock
|
||||||
|
except ImportError:
|
||||||
|
import mock
|
||||||
|
|
||||||
from validations_common.tests import base
|
from validations_common.tests import base
|
||||||
|
from validations_common.tests import fakes
|
||||||
|
|
||||||
|
from validations_common.library import advanced_format
|
||||||
|
|
||||||
|
|
||||||
class TestAdvancedFormat(base.TestCase):
|
class TestAdvancedFormat(base.TestCase):
|
||||||
|
|
|
@ -12,13 +12,17 @@
|
||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
import subprocess
|
try:
|
||||||
from unittest import mock
|
from unittest import mock
|
||||||
|
except ImportError:
|
||||||
from validations_common.library import check_package_update as cppkg
|
import mock
|
||||||
|
|
||||||
from validations_common.tests import base
|
from validations_common.tests import base
|
||||||
|
from validations_common.tests import fakes
|
||||||
|
|
||||||
|
import subprocess
|
||||||
|
|
||||||
|
from validations_common.library import check_package_update as cppkg
|
||||||
|
|
||||||
PKG_INSTALLED = "foo-package|6.1.5|1|x86_64"
|
PKG_INSTALLED = "foo-package|6.1.5|1|x86_64"
|
||||||
PKG_INVALID = "foo-package|6.1.5|x86_64"
|
PKG_INVALID = "foo-package|6.1.5|x86_64"
|
||||||
|
|
|
@ -12,9 +12,15 @@
|
||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
from unittest import mock
|
try:
|
||||||
from validations_common.library import haproxy_conf
|
from unittest import mock
|
||||||
|
except ImportError:
|
||||||
|
import mock
|
||||||
|
|
||||||
from validations_common.tests import base
|
from validations_common.tests import base
|
||||||
|
from validations_common.tests import fakes
|
||||||
|
|
||||||
|
from validations_common.library import haproxy_conf
|
||||||
|
|
||||||
|
|
||||||
class TestHaproxyConf(base.TestCase):
|
class TestHaproxyConf(base.TestCase):
|
||||||
|
|
|
@ -12,9 +12,15 @@
|
||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
from unittest import mock
|
try:
|
||||||
from validations_common.library import hiera
|
from unittest import mock
|
||||||
|
except ImportError:
|
||||||
|
import mock
|
||||||
|
|
||||||
from validations_common.tests import base
|
from validations_common.tests import base
|
||||||
|
from validations_common.tests import fakes
|
||||||
|
|
||||||
|
from validations_common.library import hiera
|
||||||
|
|
||||||
|
|
||||||
class TestHiera(base.TestCase):
|
class TestHiera(base.TestCase):
|
||||||
|
|
|
@ -19,11 +19,16 @@ test_report_entry
|
||||||
Tests for `reportentry` module.
|
Tests for `reportentry` module.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
try:
|
||||||
|
from unittest import mock
|
||||||
|
except ImportError:
|
||||||
|
import mock
|
||||||
|
|
||||||
|
from validations_common.tests import base
|
||||||
|
from validations_common.tests import fakes
|
||||||
|
|
||||||
import validations_common.library.reportentry as validation
|
import validations_common.library.reportentry as validation
|
||||||
from validations_common.tests import base
|
|
||||||
|
|
||||||
from unittest import mock
|
|
||||||
|
|
||||||
reason = "Reason #1"
|
reason = "Reason #1"
|
||||||
recommendation = ['Recommendation #1']
|
recommendation = ['Recommendation #1']
|
||||||
|
|
|
@ -23,9 +23,15 @@ Tests for `validations_read_ini` module.
|
||||||
import os
|
import os
|
||||||
import tempfile
|
import tempfile
|
||||||
|
|
||||||
import validations_common.library.validations_read_ini as validation
|
try:
|
||||||
from validations_common.tests import base
|
from unittest import mock
|
||||||
|
except ImportError:
|
||||||
|
import mock
|
||||||
|
|
||||||
|
from validations_common.tests import base
|
||||||
|
from validations_common.tests import fakes
|
||||||
|
|
||||||
|
import validations_common.library.validations_read_ini as validation
|
||||||
|
|
||||||
invalid_content = '''
|
invalid_content = '''
|
||||||
[DEFAULT#
|
[DEFAULT#
|
||||||
|
|
|
@ -12,9 +12,15 @@
|
||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
from unittest import mock
|
try:
|
||||||
from validations_common.library import warn
|
from unittest import mock
|
||||||
|
except ImportError:
|
||||||
|
import mock
|
||||||
|
|
||||||
from validations_common.tests import base
|
from validations_common.tests import base
|
||||||
|
from validations_common.tests import fakes
|
||||||
|
|
||||||
|
from validations_common.library import warn
|
||||||
|
|
||||||
|
|
||||||
class TestWarn(base.TestCase):
|
class TestWarn(base.TestCase):
|
||||||
|
|
Loading…
Reference in New Issue