test/: PEP8 compliancy (#24803)

* test/: PEP8 compliancy

- Make PEP8 compliant

* Python3 chokes on casting int to bytes (#24952)

But if we tell the formatter that the var is a number, it works
This commit is contained in:
Dag Wieers 2017-05-30 19:05:19 +02:00 committed by John R Barker
commit 4efec414e7
110 changed files with 1702 additions and 1547 deletions

View file

@ -35,6 +35,7 @@ def set_module_args(args):
fixture_path = os.path.join(os.path.dirname(__file__), 'fixtures')
fixture_data = {}
def load_fixture(name):
path = os.path.join(fixture_path, name)
@ -56,13 +57,14 @@ def load_fixture(name):
class AnsibleExitJson(Exception):
pass
class AnsibleFailJson(Exception):
pass
class TestIosModule(unittest.TestCase):
def execute_module(self, failed=False, changed=False, commands=None,
sort=True, defaults=False):
def execute_module(self, failed=False, changed=False, commands=None, sort=True, defaults=False):
self.load_fixtures(commands)
@ -110,4 +112,3 @@ class TestIosModule(unittest.TestCase):
def load_fixtures(self, commands=None):
pass

View file

@ -40,8 +40,7 @@ class TestIosBannerModule(TestIosModule):
self.mock_load_config.stop()
def load_fixtures(self, commands=None):
self.exec_command.return_value = (0,
load_fixture('ios_banner_show_banner.txt').strip(), None)
self.exec_command.return_value = (0, load_fixture('ios_banner_show_banner.txt').strip(), None)
self.load_config.return_value = dict(diff=None, session='session')
def test_ios_banner_create(self):

View file

@ -25,6 +25,7 @@ from ansible.compat.tests.mock import patch
from ansible.modules.network.ios import ios_command
from .ios_module import TestIosModule, load_fixture, set_module_args
class TestIosCommandModule(TestIosModule):
module = ios_command

View file

@ -89,19 +89,19 @@ class TestIosConfigModule(TestIosModule):
self.execute_module(changed=True, commands=commands)
def test_ios_config_before(self):
set_module_args(dict(lines=['hostname foo'], before=['test1','test2']))
set_module_args(dict(lines=['hostname foo'], before=['test1', 'test2']))
commands = ['test1', 'test2', 'hostname foo']
self.execute_module(changed=True, commands=commands, sort=False)
def test_ios_config_after(self):
set_module_args(dict(lines=['hostname foo'], after=['test1','test2']))
set_module_args(dict(lines=['hostname foo'], after=['test1', 'test2']))
commands = ['hostname foo', 'test1', 'test2']
self.execute_module(changed=True, commands=commands, sort=False)
def test_ios_config_before_after_no_change(self):
set_module_args(dict(lines=['hostname router'],
before=['test1', 'test2'],
after=['test3','test4']))
after=['test3', 'test4']))
self.execute_module()
def test_ios_config_config(self):

View file

@ -51,7 +51,6 @@ class TestIosSystemModule(TestIosModule):
commands = ['hostname foo']
self.execute_module(changed=True, commands=commands)
def test_ios_system_domain_name(self):
set_module_args(dict(domain_name=['test.com']))
commands = ['ip domain name test.com',
@ -120,4 +119,3 @@ class TestIosSystemModule(TestIosModule):
name_servers = dict(server='8.8.8.8', vrf='missing')
set_module_args(dict(name_servers=name_servers))
self.execute_module(failed=True)

View file

@ -26,6 +26,7 @@ from ansible.compat.tests.mock import patch
from ansible.modules.network.ios import _ios_template
from .ios_module import TestIosModule, load_fixture, set_module_args
class TestIosTemplateModule(TestIosModule):
module = _ios_template

View file

@ -122,5 +122,3 @@ class TestIosVrfModule(TestIosModule):
commands = ['no vrf definition test_1', 'vrf definition test_2',
'description test string']
self.execute_module(changed=True, commands=commands, sort=False)